@@ -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 |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -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 | } |
@@ -5,13 +5,24 | |||||
5 |
|
5 | |||
6 | class QCustomPlot; |
|
6 | class QCustomPlot; | |
7 | class QMouseEvent; |
|
7 | class QMouseEvent; | |
|
8 | class Unit; | |||
|
9 | class VisualizationGraphWidget; | |||
8 |
|
10 | |||
9 | class VisualizationGraphRenderingDelegate { |
|
11 | class VisualizationGraphRenderingDelegate { | |
10 | public: |
|
12 | public: | |
11 | explicit VisualizationGraphRenderingDelegate(QCustomPlot &plot); |
|
13 | /// Ctor | |
|
14 | /// @param graphWidget the graph widget to which the delegate is associated | |||
|
15 | /// @remarks the graph widget must exist throughout the life cycle of the delegate | |||
|
16 | explicit VisualizationGraphRenderingDelegate(VisualizationGraphWidget &graphWidget); | |||
12 |
|
17 | |||
13 | void onMouseMove(QMouseEvent *event) noexcept; |
|
18 | void onMouseMove(QMouseEvent *event) noexcept; | |
14 |
|
19 | |||
|
20 | /// Sets properties of the plot's axes | |||
|
21 | void setAxesProperties(const Unit &xAxisUnit, const Unit &valuesUnit) noexcept; | |||
|
22 | ||||
|
23 | /// Shows or hides graph overlay (name, close button, etc.) | |||
|
24 | void showGraphOverlay(bool show) noexcept; | |||
|
25 | ||||
15 | private: |
|
26 | private: | |
16 | class VisualizationGraphRenderingDelegatePrivate; |
|
27 | class VisualizationGraphRenderingDelegatePrivate; | |
17 | spimpl::unique_impl_ptr<VisualizationGraphRenderingDelegatePrivate> impl; |
|
28 | spimpl::unique_impl_ptr<VisualizationGraphRenderingDelegatePrivate> impl; |
@@ -13,6 +13,7 | |||||
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 | |||
@@ -23,6 +24,9 class VisualizationGraphWidget; | |||||
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 QCustomPlotSynchronizer; | |||
|
28 | friend class VisualizationGraphRenderingDelegate; | |||
|
29 | ||||
26 | public: |
|
30 | public: | |
27 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
31 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
28 | virtual ~VisualizationGraphWidget(); |
|
32 | virtual ~VisualizationGraphWidget(); | |
@@ -52,9 +56,13 signals: | |||||
52 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, |
|
56 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, | |
53 | const SqpRange &oldRange, bool synchronise); |
|
57 | const SqpRange &oldRange, bool synchronise); | |
54 |
|
58 | |||
55 |
|
||||
56 | void variableAdded(std::shared_ptr<Variable> var); |
|
59 | void variableAdded(std::shared_ptr<Variable> var); | |
57 |
|
60 | |||
|
61 | protected: | |||
|
62 | void enterEvent(QEvent *event) override; | |||
|
63 | void leaveEvent(QEvent *event) override; | |||
|
64 | ||||
|
65 | QCustomPlot &plot() noexcept; | |||
58 |
|
66 | |||
59 | private: |
|
67 | private: | |
60 | Ui::VisualizationGraphWidget *ui; |
|
68 | Ui::VisualizationGraphWidget *ui; |
@@ -56,6 +56,7 gui_sources = [ | |||||
56 | 'src/Visualization/VisualizationWidget.cpp', |
|
56 | 'src/Visualization/VisualizationWidget.cpp', | |
57 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
57 | 'src/Visualization/VisualizationZoneWidget.cpp', | |
58 | 'src/Visualization/qcustomplot.cpp', |
|
58 | 'src/Visualization/qcustomplot.cpp', | |
|
59 | 'src/Visualization/QCustomPlotSynchronizer.cpp', | |||
59 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
60 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', | |
60 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
61 | 'src/Visualization/operations/MenuBuilder.cpp', | |
61 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
62 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
@@ -5,10 +5,12 | |||||
5 | <file>icones/dataSourceProduct.png</file> |
|
5 | <file>icones/dataSourceProduct.png</file> | |
6 | <file>icones/dataSourceRoot.png</file> |
|
6 | <file>icones/dataSourceRoot.png</file> | |
7 | <file>icones/delete.png</file> |
|
7 | <file>icones/delete.png</file> | |
|
8 | <file>icones/down.png</file> | |||
8 | <file>icones/openInspector.png</file> |
|
9 | <file>icones/openInspector.png</file> | |
9 | <file>icones/next.png</file> |
|
10 | <file>icones/next.png</file> | |
10 | <file>icones/plot.png</file> |
|
11 | <file>icones/plot.png</file> | |
11 | <file>icones/previous.png</file> |
|
12 | <file>icones/previous.png</file> | |
12 | <file>icones/unplot.png</file> |
|
13 | <file>icones/unplot.png</file> | |
|
14 | <file>icones/up.png</file> | |||
13 | </qresource> |
|
15 | </qresource> | |
14 | </RCC> |
|
16 | </RCC> |
@@ -17,44 +17,6 public: | |||||
17 | void appendGraphData(const QCPGraphData &data) { mData.append(data); } |
|
17 | void appendGraphData(const QCPGraphData &data) { mData.append(data); } | |
18 | }; |
|
18 | }; | |
19 |
|
19 | |||
20 |
|
||||
21 | /// Format for datetimes on a axis |
|
|||
22 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); |
|
|||
23 |
|
||||
24 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or |
|
|||
25 | /// non-time data |
|
|||
26 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) |
|
|||
27 | { |
|
|||
28 | if (isTimeAxis) { |
|
|||
29 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); |
|
|||
30 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); |
|
|||
31 | dateTicker->setDateTimeSpec(Qt::UTC); |
|
|||
32 |
|
||||
33 | return dateTicker; |
|
|||
34 | } |
|
|||
35 | else { |
|
|||
36 | // default ticker |
|
|||
37 | return QSharedPointer<QCPAxisTicker>::create(); |
|
|||
38 | } |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | /// Sets axes properties according to the properties of a data series. Not thread safe |
|
|||
42 | template <int Dim> |
|
|||
43 | void setAxesProperties(const DataSeries<Dim> &dataSeries, QCustomPlot &plot) noexcept |
|
|||
44 | { |
|
|||
45 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
|||
46 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
|||
47 | auto setAxisProperties = [](auto axis, const auto &unit) { |
|
|||
48 | // label (unit name) |
|
|||
49 | axis->setLabel(unit.m_Name); |
|
|||
50 |
|
||||
51 | // ticker (depending on the type of unit) |
|
|||
52 | axis->setTicker(axisTicker(unit.m_TimeUnit)); |
|
|||
53 | }; |
|
|||
54 | setAxisProperties(plot.xAxis, dataSeries.xAxisUnit()); |
|
|||
55 | setAxisProperties(plot.yAxis, dataSeries.valuesUnit()); |
|
|||
56 | } |
|
|||
57 |
|
||||
58 | /** |
|
20 | /** | |
59 | * Struct used to create plottables, depending on the type of the data series from which to create |
|
21 | * Struct used to create plottables, depending on the type of the data series from which to create | |
60 | * them |
|
22 | * them | |
@@ -99,11 +61,6 struct PlottablesCreator<T, | |||||
99 | result.insert({i, graph}); |
|
61 | result.insert({i, graph}); | |
100 | } |
|
62 | } | |
101 |
|
63 | |||
102 | // Axes properties |
|
|||
103 | dataSeries.lockRead(); |
|
|||
104 | setAxesProperties(dataSeries, plot); |
|
|||
105 | dataSeries.unlock(); |
|
|||
106 |
|
||||
107 | plot.replot(); |
|
64 | plot.replot(); | |
108 |
|
65 | |||
109 | return result; |
|
66 | return result; |
@@ -1,12 +1,32 | |||||
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 | |||
|
7 | #include <Data/IDataSeries.h> | |||
|
8 | ||||
|
9 | #include <SqpApplication.h> | |||
|
10 | ||||
6 | namespace { |
|
11 | namespace { | |
7 |
|
12 | |||
|
13 | /// Name of the axes layer in QCustomPlot | |||
|
14 | const auto AXES_LAYER = QStringLiteral("axes"); | |||
|
15 | ||||
8 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); |
|
16 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); | |
9 |
|
17 | |||
|
18 | /// Format for datetimes on a axis | |||
|
19 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); | |||
|
20 | ||||
|
21 | /// Icon used to show x-axis properties | |||
|
22 | const auto HIDE_AXIS_ICON_PATH = QStringLiteral(":/icones/down.png"); | |||
|
23 | ||||
|
24 | /// Name of the overlay layer in QCustomPlot | |||
|
25 | const auto OVERLAY_LAYER = QStringLiteral("overlay"); | |||
|
26 | ||||
|
27 | /// Pixmap used to show x-axis properties | |||
|
28 | const auto SHOW_AXIS_ICON_PATH = QStringLiteral(":/icones/up.png"); | |||
|
29 | ||||
10 | const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); |
|
30 | const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); | |
11 |
|
31 | |||
12 | /// Offset used to shift the tooltip of the mouse |
|
32 | /// Offset used to shift the tooltip of the mouse | |
@@ -18,6 +38,23 const auto TOOLTIP_RECT = QRect{10, 10, 10, 10}; | |||||
18 | /// Timeout after which the tooltip is displayed |
|
38 | /// Timeout after which the tooltip is displayed | |
19 | const auto TOOLTIP_TIMEOUT = 500; |
|
39 | const auto TOOLTIP_TIMEOUT = 500; | |
20 |
|
40 | |||
|
41 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or | |||
|
42 | /// non-time data | |||
|
43 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) | |||
|
44 | { | |||
|
45 | if (isTimeAxis) { | |||
|
46 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); | |||
|
47 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); | |||
|
48 | dateTicker->setDateTimeSpec(Qt::UTC); | |||
|
49 | ||||
|
50 | return dateTicker; | |||
|
51 | } | |||
|
52 | else { | |||
|
53 | // default ticker | |||
|
54 | return QSharedPointer<QCPAxisTicker>::create(); | |||
|
55 | } | |||
|
56 | } | |||
|
57 | ||||
21 | /// Formats a data value according to the axis on which it is present |
|
58 | /// Formats a data value according to the axis on which it is present | |
22 | QString formatValue(double value, const QCPAxis &axis) |
|
59 | QString formatValue(double value, const QCPAxis &axis) | |
23 | { |
|
60 | { | |
@@ -39,25 +76,129 void initPointTracerStyle(QCPItemTracer &tracer) noexcept | |||||
39 | tracer.setBrush(Qt::black); |
|
76 | tracer.setBrush(Qt::black); | |
40 | } |
|
77 | } | |
41 |
|
78 | |||
|
79 | QPixmap pixmap(const QString &iconPath) noexcept | |||
|
80 | { | |||
|
81 | return QIcon{iconPath}.pixmap(QSize{16, 16}); | |||
|
82 | } | |||
|
83 | ||||
|
84 | void initClosePixmapStyle(QCPItemPixmap &pixmap) noexcept | |||
|
85 | { | |||
|
86 | // Icon | |||
|
87 | pixmap.setPixmap( | |||
|
88 | sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton).pixmap(QSize{16, 16})); | |||
|
89 | ||||
|
90 | // Position | |||
|
91 | pixmap.topLeft->setType(QCPItemPosition::ptAxisRectRatio); | |||
|
92 | pixmap.topLeft->setCoords(1, 0); | |||
|
93 | pixmap.setClipToAxisRect(false); | |||
|
94 | ||||
|
95 | // Can be selected | |||
|
96 | pixmap.setSelectable(true); | |||
|
97 | } | |||
|
98 | ||||
|
99 | void initXAxisPixmapStyle(QCPItemPixmap &itemPixmap) noexcept | |||
|
100 | { | |||
|
101 | // Icon | |||
|
102 | itemPixmap.setPixmap(pixmap(HIDE_AXIS_ICON_PATH)); | |||
|
103 | ||||
|
104 | // Position | |||
|
105 | itemPixmap.topLeft->setType(QCPItemPosition::ptAxisRectRatio); | |||
|
106 | itemPixmap.topLeft->setCoords(0, 1); | |||
|
107 | itemPixmap.setClipToAxisRect(false); | |||
|
108 | ||||
|
109 | // Can be selected | |||
|
110 | itemPixmap.setSelectable(true); | |||
|
111 | } | |||
|
112 | ||||
|
113 | void initTitleTextStyle(QCPItemText &text) noexcept | |||
|
114 | { | |||
|
115 | // Font and background styles | |||
|
116 | text.setColor(Qt::gray); | |||
|
117 | text.setBrush(Qt::white); | |||
|
118 | ||||
|
119 | // Position | |||
|
120 | text.setPositionAlignment(Qt::AlignTop | Qt::AlignLeft); | |||
|
121 | text.position->setType(QCPItemPosition::ptAxisRectRatio); | |||
|
122 | text.position->setCoords(0.5, 0); | |||
|
123 | } | |||
|
124 | ||||
42 | } // namespace |
|
125 | } // namespace | |
43 |
|
126 | |||
44 | struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { |
|
127 | struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { | |
45 |
explicit VisualizationGraphRenderingDelegatePrivate( |
|
128 | explicit VisualizationGraphRenderingDelegatePrivate(VisualizationGraphWidget &graphWidget) | |
46 | : m_Plot{plot}, m_PointTracer{new QCPItemTracer{&plot}}, m_TracerTimer{} |
|
129 | : m_Plot{graphWidget.plot()}, | |
|
130 | m_PointTracer{new QCPItemTracer{&m_Plot}}, | |||
|
131 | m_TracerTimer{}, | |||
|
132 | m_ClosePixmap{new QCPItemPixmap{&m_Plot}}, | |||
|
133 | m_TitleText{new QCPItemText{&m_Plot}}, | |||
|
134 | m_XAxisPixmap{new QCPItemPixmap{&m_Plot}}, | |||
|
135 | m_ShowXAxis{true}, | |||
|
136 | m_XAxisLabel{} | |||
47 | { |
|
137 | { | |
48 | initPointTracerStyle(*m_PointTracer); |
|
138 | initPointTracerStyle(*m_PointTracer); | |
49 |
|
139 | |||
50 | m_TracerTimer.setInterval(TOOLTIP_TIMEOUT); |
|
140 | m_TracerTimer.setInterval(TOOLTIP_TIMEOUT); | |
51 | m_TracerTimer.setSingleShot(true); |
|
141 | m_TracerTimer.setSingleShot(true); | |
|
142 | ||||
|
143 | // Inits "close button" in plot overlay | |||
|
144 | m_ClosePixmap->setLayer(OVERLAY_LAYER); | |||
|
145 | initClosePixmapStyle(*m_ClosePixmap); | |||
|
146 | ||||
|
147 | // Connects pixmap selection to graph widget closing | |||
|
148 | QObject::connect(m_ClosePixmap, &QCPItemPixmap::selectionChanged, | |||
|
149 | [&graphWidget](bool selected) { | |||
|
150 | if (selected) { | |||
|
151 | graphWidget.close(); | |||
|
152 | } | |||
|
153 | }); | |||
|
154 | ||||
|
155 | // Inits graph name in plot overlay | |||
|
156 | m_TitleText->setLayer(OVERLAY_LAYER); | |||
|
157 | m_TitleText->setText(graphWidget.name()); | |||
|
158 | initTitleTextStyle(*m_TitleText); | |||
|
159 | ||||
|
160 | // Inits "show x-axis button" in plot overlay | |||
|
161 | m_XAxisPixmap->setLayer(OVERLAY_LAYER); | |||
|
162 | initXAxisPixmapStyle(*m_XAxisPixmap); | |||
|
163 | ||||
|
164 | // Connects pixmap selection to graph x-axis showing/hiding | |||
|
165 | QObject::connect(m_XAxisPixmap, &QCPItemPixmap::selectionChanged, [this]() { | |||
|
166 | if (m_XAxisPixmap->selected()) { | |||
|
167 | // Changes the selection state and refreshes the x-axis | |||
|
168 | m_ShowXAxis = !m_ShowXAxis; | |||
|
169 | updateXAxisState(); | |||
|
170 | m_Plot.layer(AXES_LAYER)->replot(); | |||
|
171 | ||||
|
172 | // Deselects the x-axis pixmap and updates icon | |||
|
173 | m_XAxisPixmap->setSelected(false); | |||
|
174 | m_XAxisPixmap->setPixmap( | |||
|
175 | pixmap(m_ShowXAxis ? HIDE_AXIS_ICON_PATH : SHOW_AXIS_ICON_PATH)); | |||
|
176 | m_Plot.layer(OVERLAY_LAYER)->replot(); | |||
|
177 | } | |||
|
178 | }); | |||
|
179 | } | |||
|
180 | ||||
|
181 | /// Updates state of x-axis according to the current selection of x-axis pixmap | |||
|
182 | /// @remarks the method doesn't call plot refresh | |||
|
183 | void updateXAxisState() noexcept | |||
|
184 | { | |||
|
185 | m_Plot.xAxis->setTickLabels(m_ShowXAxis); | |||
|
186 | m_Plot.xAxis->setLabel(m_ShowXAxis ? m_XAxisLabel : QString{}); | |||
52 | } |
|
187 | } | |
53 |
|
188 | |||
54 | QCustomPlot &m_Plot; |
|
189 | QCustomPlot &m_Plot; | |
55 | QCPItemTracer *m_PointTracer; |
|
190 | QCPItemTracer *m_PointTracer; | |
56 | QTimer m_TracerTimer; |
|
191 | QTimer m_TracerTimer; | |
|
192 | QCPItemPixmap *m_ClosePixmap; /// Graph's close button | |||
|
193 | QCPItemText *m_TitleText; /// Graph's title | |||
|
194 | QCPItemPixmap *m_XAxisPixmap; | |||
|
195 | bool m_ShowXAxis; /// X-axis properties are shown or hidden | |||
|
196 | QString m_XAxisLabel; | |||
57 | }; |
|
197 | }; | |
58 |
|
198 | |||
59 |
VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( |
|
199 | VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( | |
60 | : impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(plot)} |
|
200 | VisualizationGraphWidget &graphWidget) | |
|
201 | : impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(graphWidget)} | |||
61 | { |
|
202 | { | |
62 | } |
|
203 | } | |
63 |
|
204 | |||
@@ -103,3 +244,32 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce | |||||
103 | } |
|
244 | } | |
104 | } |
|
245 | } | |
105 | } |
|
246 | } | |
|
247 | ||||
|
248 | void VisualizationGraphRenderingDelegate::setAxesProperties(const Unit &xAxisUnit, | |||
|
249 | const Unit &valuesUnit) noexcept | |||
|
250 | { | |||
|
251 | // Stores x-axis label to be able to retrieve it when x-axis pixmap is unselected | |||
|
252 | impl->m_XAxisLabel = xAxisUnit.m_Name; | |||
|
253 | ||||
|
254 | auto setAxisProperties = [](auto axis, const auto &unit) { | |||
|
255 | // label (unit name) | |||
|
256 | axis->setLabel(unit.m_Name); | |||
|
257 | ||||
|
258 | // ticker (depending on the type of unit) | |||
|
259 | axis->setTicker(axisTicker(unit.m_TimeUnit)); | |||
|
260 | }; | |||
|
261 | setAxisProperties(impl->m_Plot.xAxis, xAxisUnit); | |||
|
262 | setAxisProperties(impl->m_Plot.yAxis, valuesUnit); | |||
|
263 | ||||
|
264 | // Updates x-axis state | |||
|
265 | impl->updateXAxisState(); | |||
|
266 | ||||
|
267 | impl->m_Plot.layer(AXES_LAYER)->replot(); | |||
|
268 | } | |||
|
269 | ||||
|
270 | void VisualizationGraphRenderingDelegate::showGraphOverlay(bool show) noexcept | |||
|
271 | { | |||
|
272 | auto overlay = impl->m_Plot.layer(OVERLAY_LAYER); | |||
|
273 | overlay->setVisible(show); | |||
|
274 | overlay->replot(); | |||
|
275 | } |
@@ -28,11 +28,15 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |||||
28 |
|
28 | |||
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
30 |
|
30 | |||
31 | explicit VisualizationGraphWidgetPrivate() |
|
31 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
32 | : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr} |
|
32 | : m_Name{name}, | |
|
33 | m_DoAcquisition{true}, | |||
|
34 | m_IsCalibration{false}, | |||
|
35 | m_RenderingDelegate{nullptr} | |||
33 | { |
|
36 | { | |
34 | } |
|
37 | } | |
35 |
|
38 | |||
|
39 | QString m_Name; | |||
36 | // 1 variable -> n qcpplot |
|
40 | // 1 variable -> n qcpplot | |
37 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
41 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
38 | bool m_DoAcquisition; |
|
42 | bool m_DoAcquisition; | |
@@ -45,26 +49,22 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
45 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
49 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
46 | : QWidget{parent}, |
|
50 | : QWidget{parent}, | |
47 | ui{new Ui::VisualizationGraphWidget}, |
|
51 | ui{new Ui::VisualizationGraphWidget}, | |
48 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
52 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
49 | { |
|
53 | { | |
50 | ui->setupUi(this); |
|
54 | ui->setupUi(this); | |
51 |
|
55 | |||
52 | // The delegate must be initialized after the ui as it uses the plot |
|
|||
53 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget); |
|
|||
54 |
|
||||
55 | ui->graphNameLabel->setText(name); |
|
|||
56 |
|
||||
57 | // 'Close' options : widget is deleted when closed |
|
56 | // 'Close' options : widget is deleted when closed | |
58 | setAttribute(Qt::WA_DeleteOnClose); |
|
57 | setAttribute(Qt::WA_DeleteOnClose); | |
59 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
|||
60 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
|||
61 |
|
58 | |||
62 | // Set qcpplot properties : |
|
59 | // Set qcpplot properties : | |
63 | // - Drag (on x-axis) and zoom are enabled |
|
60 | // - Drag (on x-axis) and zoom are enabled | |
64 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
61 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
65 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
62 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems); | |
66 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
63 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
67 |
|
64 | |||
|
65 | // The delegate must be initialized after the ui as it uses the plot | |||
|
66 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |||
|
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); | |
@@ -103,6 +103,20 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, S | |||||
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 | // Set axes properties according to the units of the data series | |||
|
107 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers | |||
|
108 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph | |||
|
109 | auto xAxisUnit = Unit{}; | |||
|
110 | auto valuesUnit = Unit{}; | |||
|
111 | ||||
|
112 | if (auto dataSeries = variable->dataSeries()) { | |||
|
113 | dataSeries->lockRead(); | |||
|
114 | xAxisUnit = dataSeries->xAxisUnit(); | |||
|
115 | valuesUnit = dataSeries->valuesUnit(); | |||
|
116 | dataSeries->unlock(); | |||
|
117 | } | |||
|
118 | impl->m_RenderingDelegate->setAxesProperties(xAxisUnit, valuesUnit); | |||
|
119 | ||||
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
120 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
107 |
|
121 | |||
108 | auto varRange = variable->range(); |
|
122 | auto varRange = variable->range(); | |
@@ -201,7 +215,24 bool VisualizationGraphWidget::contains(const Variable &variable) const | |||||
201 |
|
215 | |||
202 | QString VisualizationGraphWidget::name() const |
|
216 | QString VisualizationGraphWidget::name() const | |
203 | { |
|
217 | { | |
204 |
return |
|
218 | return impl->m_Name; | |
|
219 | } | |||
|
220 | ||||
|
221 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |||
|
222 | { | |||
|
223 | Q_UNUSED(event); | |||
|
224 | impl->m_RenderingDelegate->showGraphOverlay(true); | |||
|
225 | } | |||
|
226 | ||||
|
227 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |||
|
228 | { | |||
|
229 | Q_UNUSED(event); | |||
|
230 | impl->m_RenderingDelegate->showGraphOverlay(false); | |||
|
231 | } | |||
|
232 | ||||
|
233 | QCustomPlot &VisualizationGraphWidget::plot() noexcept | |||
|
234 | { | |||
|
235 | return *ui->widget; | |||
205 | } |
|
236 | } | |
206 |
|
237 | |||
207 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
238 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
@@ -1,7 +1,7 | |||||
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 | |||
@@ -38,8 +38,13 QString defaultGraphName(const QLayout &layout) | |||||
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) | |
@@ -68,6 +73,9 VisualizationZoneWidget::~VisualizationZoneWidget() | |||||
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 |
@@ -14,50 +14,18 | |||||
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout"> | |
17 | <item> |
|
17 | <property name="leftMargin"> | |
18 | <widget class="QWidget" name="infobar" native="true"> |
|
18 | <number>0</number> | |
19 | <layout class="QHBoxLayout" name="horizontalLayout_2"> |
|
19 | </property> | |
20 |
|
|
20 | <property name="topMargin"> | |
21 |
|
|
21 | <number>0</number> | |
22 |
|
|
22 | </property> | |
23 |
|
|
23 | <property name="rightMargin"> | |
24 |
|
|
24 | <number>0</number> | |
25 |
|
|
25 | </property> | |
26 |
|
|
26 | <property name="bottomMargin"> | |
27 |
|
|
27 | <number>0</number> | |
28 |
|
|
28 | </property> | |
29 | <property name="bottomMargin"> |
|
|||
30 | <number>0</number> |
|
|||
31 | </property> |
|
|||
32 | <item> |
|
|||
33 | <widget class="QLabel" name="graphNameLabel"> |
|
|||
34 | <property name="styleSheet"> |
|
|||
35 | <string notr="true">font: 75 9pt "MS Shell Dlg 2";</string> |
|
|||
36 | </property> |
|
|||
37 | <property name="text"> |
|
|||
38 | <string>TextLabel</string> |
|
|||
39 | </property> |
|
|||
40 | <property name="textFormat"> |
|
|||
41 | <enum>Qt::AutoText</enum> |
|
|||
42 | </property> |
|
|||
43 | <property name="alignment"> |
|
|||
44 | <set>Qt::AlignCenter</set> |
|
|||
45 | </property> |
|
|||
46 | </widget> |
|
|||
47 | </item> |
|
|||
48 | <item> |
|
|||
49 | <widget class="QToolButton" name="closeButton"> |
|
|||
50 | <property name="styleSheet"> |
|
|||
51 | <string notr="true">background-color: transparent;</string> |
|
|||
52 | </property> |
|
|||
53 | <property name="text"> |
|
|||
54 | <string>Close</string> |
|
|||
55 | </property> |
|
|||
56 | </widget> |
|
|||
57 | </item> |
|
|||
58 | </layout> |
|
|||
59 | </widget> |
|
|||
60 | </item> |
|
|||
61 | <item> |
|
29 | <item> | |
62 | <widget class="QCustomPlot" name="widget" native="true"> |
|
30 | <widget class="QCustomPlot" name="widget" native="true"> | |
63 | <property name="sizePolicy"> |
|
31 | <property name="sizePolicy"> |
@@ -46,7 +46,23 | |||||
46 | <height>300</height> |
|
46 | <height>300</height> | |
47 | </rect> |
|
47 | </rect> | |
48 | </property> |
|
48 | </property> | |
49 |
<layout class="QVBoxLayout" name="verticalLayout_3" |
|
49 | <layout class="QVBoxLayout" name="verticalLayout_3"> | |
|
50 | <property name="spacing"> | |||
|
51 | <number>3</number> | |||
|
52 | </property> | |||
|
53 | <property name="leftMargin"> | |||
|
54 | <number>0</number> | |||
|
55 | </property> | |||
|
56 | <property name="topMargin"> | |||
|
57 | <number>0</number> | |||
|
58 | </property> | |||
|
59 | <property name="rightMargin"> | |||
|
60 | <number>0</number> | |||
|
61 | </property> | |||
|
62 | <property name="bottomMargin"> | |||
|
63 | <number>0</number> | |||
|
64 | </property> | |||
|
65 | </layout> | |||
50 | </widget> |
|
66 | </widget> | |
51 | </widget> |
|
67 | </widget> | |
52 | </item> |
|
68 | </item> |
@@ -14,6 +14,18 | |||||
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout"> | |
|
17 | <property name="leftMargin"> | |||
|
18 | <number>0</number> | |||
|
19 | </property> | |||
|
20 | <property name="topMargin"> | |||
|
21 | <number>0</number> | |||
|
22 | </property> | |||
|
23 | <property name="rightMargin"> | |||
|
24 | <number>0</number> | |||
|
25 | </property> | |||
|
26 | <property name="bottomMargin"> | |||
|
27 | <number>0</number> | |||
|
28 | </property> | |||
17 | <item> |
|
29 | <item> | |
18 | <widget class="QTabWidget" name="tabWidget"> |
|
30 | <widget class="QTabWidget" name="tabWidget"> | |
19 | <property name="currentIndex"> |
|
31 | <property name="currentIndex"> |
@@ -14,6 +14,21 | |||||
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |
|
17 | <property name="spacing"> | |||
|
18 | <number>0</number> | |||
|
19 | </property> | |||
|
20 | <property name="leftMargin"> | |||
|
21 | <number>0</number> | |||
|
22 | </property> | |||
|
23 | <property name="topMargin"> | |||
|
24 | <number>0</number> | |||
|
25 | </property> | |||
|
26 | <property name="rightMargin"> | |||
|
27 | <number>0</number> | |||
|
28 | </property> | |||
|
29 | <property name="bottomMargin"> | |||
|
30 | <number>0</number> | |||
|
31 | </property> | |||
17 | <item> |
|
32 | <item> | |
18 | <widget class="QWidget" name="infobar" native="true"> |
|
33 | <widget class="QWidget" name="infobar" native="true"> | |
19 | <property name="sizePolicy"> |
|
34 | <property name="sizePolicy"> | |
@@ -23,6 +38,9 | |||||
23 | </sizepolicy> |
|
38 | </sizepolicy> | |
24 | </property> |
|
39 | </property> | |
25 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
40 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
|
41 | <property name="spacing"> | |||
|
42 | <number>0</number> | |||
|
43 | </property> | |||
26 | <property name="leftMargin"> |
|
44 | <property name="leftMargin"> | |
27 | <number>0</number> |
|
45 | <number>0</number> | |
28 | </property> |
|
46 | </property> | |
@@ -76,7 +94,20 | |||||
76 | <property name="lineWidth"> |
|
94 | <property name="lineWidth"> | |
77 | <number>1</number> |
|
95 | <number>1</number> | |
78 | </property> |
|
96 | </property> | |
79 |
<layout class="QVBoxLayout" name="verticalLayout" |
|
97 | <layout class="QVBoxLayout" name="verticalLayout"> | |
|
98 | <property name="leftMargin"> | |||
|
99 | <number>0</number> | |||
|
100 | </property> | |||
|
101 | <property name="topMargin"> | |||
|
102 | <number>0</number> | |||
|
103 | </property> | |||
|
104 | <property name="rightMargin"> | |||
|
105 | <number>0</number> | |||
|
106 | </property> | |||
|
107 | <property name="bottomMargin"> | |||
|
108 | <number>0</number> | |||
|
109 | </property> | |||
|
110 | </layout> | |||
80 | </widget> |
|
111 | </widget> | |
81 | </item> |
|
112 | </item> | |
82 | </layout> |
|
113 | </layout> |
General Comments 0
You need to be logged in to leave comments.
Login now