@@ -1,1053 +1,1057 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationCursorItem.h" |
|
3 | #include "Visualization/VisualizationCursorItem.h" | |
4 | #include "Visualization/VisualizationDefs.h" |
|
4 | #include "Visualization/VisualizationDefs.h" | |
5 | #include "Visualization/VisualizationGraphHelper.h" |
|
5 | #include "Visualization/VisualizationGraphHelper.h" | |
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" |
|
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" | |
8 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
8 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
9 | #include "Visualization/VisualizationSelectionZoneManager.h" |
|
9 | #include "Visualization/VisualizationSelectionZoneManager.h" | |
10 | #include "Visualization/VisualizationWidget.h" |
|
10 | #include "Visualization/VisualizationWidget.h" | |
11 | #include "Visualization/VisualizationZoneWidget.h" |
|
11 | #include "Visualization/VisualizationZoneWidget.h" | |
12 | #include "ui_VisualizationGraphWidget.h" |
|
12 | #include "ui_VisualizationGraphWidget.h" | |
13 |
|
13 | |||
14 | #include <Actions/ActionsGuiController.h> |
|
14 | #include <Actions/ActionsGuiController.h> | |
15 | #include <Common/MimeTypesDef.h> |
|
15 | #include <Common/MimeTypesDef.h> | |
16 | #include <Data/ArrayData.h> |
|
16 | #include <Data/ArrayData.h> | |
17 | #include <Data/IDataSeries.h> |
|
17 | #include <Data/IDataSeries.h> | |
18 | #include <Data/SpectrogramSeries.h> |
|
18 | #include <Data/SpectrogramSeries.h> | |
19 | #include <DragAndDrop/DragDropGuiController.h> |
|
19 | #include <DragAndDrop/DragDropGuiController.h> | |
20 | #include <Settings/SqpSettingsDefs.h> |
|
20 | #include <Settings/SqpSettingsDefs.h> | |
21 | #include <SqpApplication.h> |
|
21 | #include <SqpApplication.h> | |
22 | #include <Time/TimeController.h> |
|
22 | #include <Time/TimeController.h> | |
23 | #include <Variable/Variable.h> |
|
23 | #include <Variable/Variable.h> | |
24 | #include <Variable/VariableController.h> |
|
24 | #include <Variable/VariableController.h> | |
25 |
|
25 | |||
26 | #include <unordered_map> |
|
26 | #include <unordered_map> | |
27 |
|
27 | |||
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
29 |
|
29 | |||
30 | namespace { |
|
30 | namespace { | |
31 |
|
31 | |||
32 | /// Key pressed to enable drag&drop in all modes |
|
32 | /// Key pressed to enable drag&drop in all modes | |
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; |
|
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; | |
34 |
|
34 | |||
35 | /// Key pressed to enable zoom on horizontal axis |
|
35 | /// Key pressed to enable zoom on horizontal axis | |
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
37 |
|
37 | |||
38 | /// Key pressed to enable zoom on vertical axis |
|
38 | /// Key pressed to enable zoom on vertical axis | |
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; |
|
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
40 |
|
40 | |||
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range |
|
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
42 | const auto PAN_SPEED = 5; |
|
42 | const auto PAN_SPEED = 5; | |
43 |
|
43 | |||
44 | /// Key pressed to enable a calibration pan |
|
44 | /// Key pressed to enable a calibration pan | |
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; |
|
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
46 |
|
46 | |||
47 | /// Key pressed to enable multi selection of selection zones |
|
47 | /// Key pressed to enable multi selection of selection zones | |
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; |
|
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; | |
49 |
|
49 | |||
50 | /// Minimum size for the zoom box, in percentage of the axis range |
|
50 | /// Minimum size for the zoom box, in percentage of the axis range | |
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; |
|
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; | |
52 |
|
52 | |||
53 | /// Format of the dates appearing in the label of a cursor |
|
53 | /// Format of the dates appearing in the label of a cursor | |
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); |
|
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); | |
55 |
|
55 | |||
56 | } // namespace |
|
56 | } // namespace | |
57 |
|
57 | |||
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
59 |
|
59 | |||
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
61 | : m_Name{name}, |
|
61 | : m_Name{name}, | |
62 | m_Flags{GraphFlag::EnableAll}, |
|
62 | m_Flags{GraphFlag::EnableAll}, | |
63 | m_IsCalibration{false}, |
|
63 | m_IsCalibration{false}, | |
64 | m_RenderingDelegate{nullptr} |
|
64 | m_RenderingDelegate{nullptr} | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, |
|
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, | |
69 | const SqpRange &range) |
|
69 | const SqpRange &range) | |
70 | { |
|
70 | { | |
71 | VisualizationGraphHelper::updateData(plottables, variable, range); |
|
71 | VisualizationGraphHelper::updateData(plottables, variable, range); | |
72 |
|
72 | |||
73 | // Prevents that data has changed to update rendering |
|
73 | // Prevents that data has changed to update rendering | |
74 | m_RenderingDelegate->onPlotUpdated(); |
|
74 | m_RenderingDelegate->onPlotUpdated(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | QString m_Name; |
|
77 | QString m_Name; | |
78 | // 1 variable -> n qcpplot |
|
78 | // 1 variable -> n qcpplot | |
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
80 | GraphFlags m_Flags; |
|
80 | GraphFlags m_Flags; | |
81 | bool m_IsCalibration; |
|
81 | bool m_IsCalibration; | |
82 | /// Delegate used to attach rendering features to the plot |
|
82 | /// Delegate used to attach rendering features to the plot | |
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
84 |
|
84 | |||
85 | QCPItemRect *m_DrawingZoomRect = nullptr; |
|
85 | QCPItemRect *m_DrawingZoomRect = nullptr; | |
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; |
|
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; | |
87 |
|
87 | |||
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; | |
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; | |
90 |
|
90 | |||
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; |
|
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; | |
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; |
|
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; |
|
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
94 |
|
94 | |||
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even |
|
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even | |
96 |
|
96 | |||
97 | bool m_VariableAutoRangeOnInit = true; |
|
97 | bool m_VariableAutoRangeOnInit = true; | |
98 |
|
98 | |||
99 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) |
|
99 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
100 | { |
|
100 | { | |
101 | removeDrawingRect(plot); |
|
101 | removeDrawingRect(plot); | |
102 |
|
102 | |||
103 | auto axisPos = posToAxisPos(pos, plot); |
|
103 | auto axisPos = posToAxisPos(pos, plot); | |
104 |
|
104 | |||
105 | m_DrawingZoomRect = new QCPItemRect{&plot}; |
|
105 | m_DrawingZoomRect = new QCPItemRect{&plot}; | |
106 | QPen p; |
|
106 | QPen p; | |
107 | p.setWidth(2); |
|
107 | p.setWidth(2); | |
108 | m_DrawingZoomRect->setPen(p); |
|
108 | m_DrawingZoomRect->setPen(p); | |
109 |
|
109 | |||
110 | m_DrawingZoomRect->topLeft->setCoords(axisPos); |
|
110 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
111 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
111 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void removeDrawingRect(QCustomPlot &plot) |
|
114 | void removeDrawingRect(QCustomPlot &plot) | |
115 | { |
|
115 | { | |
116 | if (m_DrawingZoomRect) { |
|
116 | if (m_DrawingZoomRect) { | |
117 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot |
|
117 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
118 | m_DrawingZoomRect = nullptr; |
|
118 | m_DrawingZoomRect = nullptr; | |
119 | plot.replot(QCustomPlot::rpQueuedReplot); |
|
119 | plot.replot(QCustomPlot::rpQueuedReplot); | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) |
|
123 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) | |
124 | { |
|
124 | { | |
125 | endDrawingZone(graph); |
|
125 | endDrawingZone(graph); | |
126 |
|
126 | |||
127 | auto axisPos = posToAxisPos(pos, graph->plot()); |
|
127 | auto axisPos = posToAxisPos(pos, graph->plot()); | |
128 |
|
128 | |||
129 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; |
|
129 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; | |
130 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); |
|
130 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
131 | m_DrawingZone->setEditionEnabled(false); |
|
131 | m_DrawingZone->setEditionEnabled(false); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void endDrawingZone(VisualizationGraphWidget *graph) |
|
134 | void endDrawingZone(VisualizationGraphWidget *graph) | |
135 | { |
|
135 | { | |
136 | if (m_DrawingZone) { |
|
136 | if (m_DrawingZone) { | |
137 | auto drawingZoneRange = m_DrawingZone->range(); |
|
137 | auto drawingZoneRange = m_DrawingZone->range(); | |
138 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { |
|
138 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { | |
139 | m_DrawingZone->setEditionEnabled(true); |
|
139 | m_DrawingZone->setEditionEnabled(true); | |
140 | addSelectionZone(m_DrawingZone); |
|
140 | addSelectionZone(m_DrawingZone); | |
141 | } |
|
141 | } | |
142 | else { |
|
142 | else { | |
143 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot |
|
143 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | graph->plot().replot(QCustomPlot::rpQueuedReplot); |
|
146 | graph->plot().replot(QCustomPlot::rpQueuedReplot); | |
147 | m_DrawingZone = nullptr; |
|
147 | m_DrawingZone = nullptr; | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void setSelectionZonesEditionEnabled(bool value) |
|
151 | void setSelectionZonesEditionEnabled(bool value) | |
152 | { |
|
152 | { | |
153 | for (auto s : m_SelectionZones) { |
|
153 | for (auto s : m_SelectionZones) { | |
154 | s->setEditionEnabled(value); |
|
154 | s->setEditionEnabled(value); | |
155 | } |
|
155 | } | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } |
|
158 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } | |
159 |
|
159 | |||
160 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, |
|
160 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, | |
161 | const QCustomPlot &plot) const |
|
161 | const QCustomPlot &plot) const | |
162 | { |
|
162 | { | |
163 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; |
|
163 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; | |
164 | auto minDistanceToZone = -1; |
|
164 | auto minDistanceToZone = -1; | |
165 | for (auto zone : m_SelectionZones) { |
|
165 | for (auto zone : m_SelectionZones) { | |
166 | auto distanceToZone = zone->selectTest(pos, false); |
|
166 | auto distanceToZone = zone->selectTest(pos, false); | |
167 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) |
|
167 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) | |
168 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
168 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
169 | selectionZoneItemUnderCursor = zone; |
|
169 | selectionZoneItemUnderCursor = zone; | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | return selectionZoneItemUnderCursor; |
|
173 | return selectionZoneItemUnderCursor; | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, |
|
176 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, | |
177 | const QCustomPlot &plot) const |
|
177 | const QCustomPlot &plot) const | |
178 | { |
|
178 | { | |
179 | QVector<VisualizationSelectionZoneItem *> zones; |
|
179 | QVector<VisualizationSelectionZoneItem *> zones; | |
180 | for (auto zone : m_SelectionZones) { |
|
180 | for (auto zone : m_SelectionZones) { | |
181 | auto distanceToZone = zone->selectTest(pos, false); |
|
181 | auto distanceToZone = zone->selectTest(pos, false); | |
182 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
182 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
183 | zones << zone; |
|
183 | zones << zone; | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | return zones; |
|
187 | return zones; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) |
|
190 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) | |
191 | { |
|
191 | { | |
192 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { |
|
192 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { | |
193 | zone->moveToTop(); |
|
193 | zone->moveToTop(); | |
194 | m_SelectionZones.removeAll(zone); |
|
194 | m_SelectionZones.removeAll(zone); | |
195 | m_SelectionZones.append(zone); |
|
195 | m_SelectionZones.append(zone); | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const |
|
199 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const | |
200 | { |
|
200 | { | |
201 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
201 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
202 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
202 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
203 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; |
|
203 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const |
|
206 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const | |
207 | { |
|
207 | { | |
208 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
208 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
209 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
209 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
210 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
210 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); | |
211 | } |
|
211 | } | |
212 | }; |
|
212 | }; | |
213 |
|
213 | |||
214 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
214 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
215 | : VisualizationDragWidget{parent}, |
|
215 | : VisualizationDragWidget{parent}, | |
216 | ui{new Ui::VisualizationGraphWidget}, |
|
216 | ui{new Ui::VisualizationGraphWidget}, | |
217 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
217 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
218 | { |
|
218 | { | |
219 | ui->setupUi(this); |
|
219 | ui->setupUi(this); | |
220 |
|
220 | |||
221 | // 'Close' options : widget is deleted when closed |
|
221 | // 'Close' options : widget is deleted when closed | |
222 | setAttribute(Qt::WA_DeleteOnClose); |
|
222 | setAttribute(Qt::WA_DeleteOnClose); | |
223 |
|
223 | |||
224 | // Set qcpplot properties : |
|
224 | // Set qcpplot properties : | |
225 | // - zoom is enabled |
|
225 | // - zoom is enabled | |
226 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
226 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
227 | ui->widget->setInteractions(QCP::iRangeZoom); |
|
227 | ui->widget->setInteractions(QCP::iRangeZoom); | |
228 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); |
|
228 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); | |
229 |
|
229 | |||
230 | // The delegate must be initialized after the ui as it uses the plot |
|
230 | // The delegate must be initialized after the ui as it uses the plot | |
231 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
231 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
232 |
|
232 | |||
233 | // Init the cursors |
|
233 | // Init the cursors | |
234 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
234 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
235 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); |
|
235 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); | |
236 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
236 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
237 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); |
|
237 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); | |
238 |
|
238 | |||
239 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
239 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
240 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
240 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
241 | &VisualizationGraphWidget::onMouseRelease); |
|
241 | &VisualizationGraphWidget::onMouseRelease); | |
242 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
242 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
243 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
243 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
244 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, |
|
244 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, | |
245 | &VisualizationGraphWidget::onMouseDoubleClick); |
|
245 | &VisualizationGraphWidget::onMouseDoubleClick); | |
246 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
246 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
247 | &QCPAxis::rangeChanged), |
|
247 | &QCPAxis::rangeChanged), | |
248 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
248 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
249 |
|
249 | |||
250 | // Activates menu when right clicking on the graph |
|
250 | // Activates menu when right clicking on the graph | |
251 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
251 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
252 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
252 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
253 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
253 | &VisualizationGraphWidget::onGraphMenuRequested); | |
254 |
|
254 | |||
255 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
255 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
256 | &VariableController::onRequestDataLoading); |
|
256 | &VariableController::onRequestDataLoading); | |
257 |
|
257 | |||
258 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
258 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
259 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
259 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
260 |
|
260 | |||
261 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. |
|
261 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. | |
262 | plot().setPlottingHint(QCP::phFastPolylines, true); |
|
262 | plot().setPlottingHint(QCP::phFastPolylines, true); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
266 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
267 | { |
|
267 | { | |
268 | delete ui; |
|
268 | delete ui; | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
271 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
272 | { |
|
272 | { | |
273 | auto parent = parentWidget(); |
|
273 | auto parent = parentWidget(); | |
274 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
274 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { | |
275 | parent = parent->parentWidget(); |
|
275 | parent = parent->parentWidget(); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
278 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const |
|
281 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const | |
282 | { |
|
282 | { | |
283 | auto parent = parentWidget(); |
|
283 | auto parent = parentWidget(); | |
284 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { |
|
284 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { | |
285 | parent = parent->parentWidget(); |
|
285 | parent = parent->parentWidget(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | return qobject_cast<VisualizationWidget *>(parent); |
|
288 | return qobject_cast<VisualizationWidget *>(parent); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void VisualizationGraphWidget::setFlags(GraphFlags flags) |
|
291 | void VisualizationGraphWidget::setFlags(GraphFlags flags) | |
292 | { |
|
292 | { | |
293 | impl->m_Flags = std::move(flags); |
|
293 | impl->m_Flags = std::move(flags); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
296 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
297 | { |
|
297 | { | |
298 | /// Lambda used to set graph's units and range according to the variable passed in parameter |
|
298 | /// Lambda used to set graph's units and range according to the variable passed in parameter | |
299 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { |
|
299 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { | |
300 | impl->m_RenderingDelegate->setAxesUnits(*variable); |
|
300 | impl->m_RenderingDelegate->setAxesUnits(*variable); | |
301 |
|
301 | |||
302 | this->setFlags(GraphFlag::DisableAll); |
|
302 | this->setFlags(GraphFlag::DisableAll); | |
303 | setGraphRange(range); |
|
303 | setGraphRange(range); | |
304 | this->setFlags(GraphFlag::EnableAll); |
|
304 | this->setFlags(GraphFlag::EnableAll); | |
305 | emit requestDataLoading({variable}, range, false); |
|
305 | emit requestDataLoading({variable}, range, false); | |
306 | }; |
|
306 | }; | |
307 |
|
307 | |||
308 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
308 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
309 |
|
309 | |||
310 | // Calls update of graph's range and units when the data of the variable have been initialized. |
|
310 | // Calls update of graph's range and units when the data of the variable have been initialized. | |
311 | // Note: we use QueuedConnection here as the update event must be called in the UI thread |
|
311 | // Note: we use QueuedConnection here as the update event must be called in the UI thread | |
312 | connect(variable.get(), &Variable::dataInitialized, this, |
|
312 | connect(variable.get(), &Variable::dataInitialized, this, | |
313 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { |
|
313 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { | |
314 | if (auto var = varW.lock()) { |
|
314 | if (auto var = varW.lock()) { | |
315 | // If the variable is the first added in the graph, we load its range |
|
315 | // If the variable is the first added in the graph, we load its range | |
316 | auto firstVariableInGraph = range == INVALID_RANGE; |
|
316 | auto firstVariableInGraph = range == INVALID_RANGE; | |
317 | auto loadedRange = graphRange(); |
|
317 | auto loadedRange = graphRange(); | |
318 | if (impl->m_VariableAutoRangeOnInit) { |
|
318 | if (impl->m_VariableAutoRangeOnInit) { | |
319 | loadedRange = firstVariableInGraph ? var->range() : range; |
|
319 | loadedRange = firstVariableInGraph ? var->range() : range; | |
320 | } |
|
320 | } | |
321 | loadRange(var, loadedRange); |
|
321 | loadRange(var, loadedRange); | |
322 | setYRange(var); |
|
322 | setYRange(var); | |
323 | } |
|
323 | } | |
324 | }, |
|
324 | }, | |
325 | Qt::QueuedConnection); |
|
325 | Qt::QueuedConnection); | |
326 |
|
326 | |||
327 | // Uses delegate to create the qcpplot components according to the variable |
|
327 | // Uses delegate to create the qcpplot components according to the variable | |
328 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
328 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
329 |
|
329 | |||
330 | // Sets graph properties |
|
330 | // Sets graph properties | |
331 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); |
|
331 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); | |
332 |
|
332 | |||
333 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
333 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
334 |
|
334 | |||
335 | // If the variable already has its data loaded, load its units and its range in the graph |
|
335 | // If the variable already has its data loaded, load its units and its range in the graph | |
336 | if (variable->dataSeries() != nullptr) { |
|
336 | if (variable->dataSeries() != nullptr) { | |
337 | loadRange(variable, range); |
|
337 | loadRange(variable, range); | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | emit variableAdded(variable); |
|
340 | emit variableAdded(variable); | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
343 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
344 | { |
|
344 | { | |
345 | // Each component associated to the variable : |
|
345 | // Each component associated to the variable : | |
346 | // - is removed from qcpplot (which deletes it) |
|
346 | // - is removed from qcpplot (which deletes it) | |
347 | // - is no longer referenced in the map |
|
347 | // - is no longer referenced in the map | |
348 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
348 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
349 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
349 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
350 | emit variableAboutToBeRemoved(variable); |
|
350 | emit variableAboutToBeRemoved(variable); | |
351 |
|
351 | |||
352 | auto &plottablesMap = variableIt->second; |
|
352 | auto &plottablesMap = variableIt->second; | |
353 |
|
353 | |||
354 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
354 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
355 | plottableIt != plottableEnd;) { |
|
355 | plottableIt != plottableEnd;) { | |
356 | ui->widget->removePlottable(plottableIt->second); |
|
356 | ui->widget->removePlottable(plottableIt->second); | |
357 | plottableIt = plottablesMap.erase(plottableIt); |
|
357 | plottableIt = plottablesMap.erase(plottableIt); | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
360 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | // Updates graph |
|
363 | // Updates graph | |
364 | ui->widget->replot(); |
|
364 | ui->widget->replot(); | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
367 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
368 | { |
|
368 | { | |
369 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
369 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
370 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
370 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
371 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
371 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
372 | variables << it->first; |
|
372 | variables << it->first; | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | return variables; |
|
375 | return variables; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) |
|
378 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
379 | { |
|
379 | { | |
380 | if (!variable) { |
|
380 | if (!variable) { | |
381 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
381 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
382 | return; |
|
382 | return; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); |
|
385 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
388 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
389 | { |
|
389 | { | |
390 | auto graphRange = ui->widget->xAxis->range(); |
|
390 | auto graphRange = ui->widget->xAxis->range(); | |
391 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
391 | return SqpRange{graphRange.lower, graphRange.upper}; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) |
|
394 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) | |
395 | { |
|
395 | { | |
396 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
396 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
397 |
|
397 | |||
398 | if (calibration) { |
|
398 | if (calibration) { | |
399 | impl->m_IsCalibration = true; |
|
399 | impl->m_IsCalibration = true; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
402 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
403 | ui->widget->replot(); |
|
403 | ui->widget->replot(); | |
404 |
|
404 | |||
405 | if (calibration) { |
|
405 | if (calibration) { | |
406 | impl->m_IsCalibration = false; |
|
406 | impl->m_IsCalibration = false; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
409 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) |
|
412 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) | |
413 | { |
|
413 | { | |
414 | impl->m_VariableAutoRangeOnInit = value; |
|
414 | impl->m_VariableAutoRangeOnInit = value; | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
417 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const | |
418 | { |
|
418 | { | |
419 | QVector<SqpRange> ranges; |
|
419 | QVector<SqpRange> ranges; | |
420 | for (auto zone : impl->m_SelectionZones) { |
|
420 | for (auto zone : impl->m_SelectionZones) { | |
421 | ranges << zone->range(); |
|
421 | ranges << zone->range(); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | return ranges; |
|
424 | return ranges; | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) |
|
427 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) | |
428 | { |
|
428 | { | |
429 | for (const auto &range : ranges) { |
|
429 | for (const auto &range : ranges) { | |
430 | // note: ownership is transfered to QCustomPlot |
|
430 | // note: ownership is transfered to QCustomPlot | |
431 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
431 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
432 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
432 | zone->setRange(range.m_TStart, range.m_TEnd); | |
433 | impl->addSelectionZone(zone); |
|
433 | impl->addSelectionZone(zone); | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
436 | plot().replot(QCustomPlot::rpQueuedReplot); | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, |
|
439 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, | |
440 | const SqpRange &range) |
|
440 | const SqpRange &range) | |
441 | { |
|
441 | { | |
442 | // note: ownership is transfered to QCustomPlot |
|
442 | // note: ownership is transfered to QCustomPlot | |
443 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
443 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
444 | zone->setName(name); |
|
444 | zone->setName(name); | |
445 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
445 | zone->setRange(range.m_TStart, range.m_TEnd); | |
446 | impl->addSelectionZone(zone); |
|
446 | impl->addSelectionZone(zone); | |
447 |
|
447 | |||
448 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
448 | plot().replot(QCustomPlot::rpQueuedReplot); | |
449 |
|
449 | |||
450 | return zone; |
|
450 | return zone; | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) |
|
453 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) | |
454 | { |
|
454 | { | |
455 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
455 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
456 |
|
456 | |||
457 | if (impl->m_HoveredZone == selectionZone) { |
|
457 | if (impl->m_HoveredZone == selectionZone) { | |
458 | impl->m_HoveredZone = nullptr; |
|
458 | impl->m_HoveredZone = nullptr; | |
459 | setCursor(Qt::ArrowCursor); |
|
459 | setCursor(Qt::ArrowCursor); | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | impl->m_SelectionZones.removeAll(selectionZone); |
|
462 | impl->m_SelectionZones.removeAll(selectionZone); | |
463 | plot().removeItem(selectionZone); |
|
463 | plot().removeItem(selectionZone); | |
464 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
464 | plot().replot(QCustomPlot::rpQueuedReplot); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | void VisualizationGraphWidget::undoZoom() |
|
467 | void VisualizationGraphWidget::undoZoom() | |
468 | { |
|
468 | { | |
469 | auto zoom = impl->m_ZoomStack.pop(); |
|
469 | auto zoom = impl->m_ZoomStack.pop(); | |
470 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
470 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
471 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
471 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
472 |
|
472 | |||
473 | axisX->setRange(zoom.first); |
|
473 | axisX->setRange(zoom.first); | |
474 | axisY->setRange(zoom.second); |
|
474 | axisY->setRange(zoom.second); | |
475 |
|
475 | |||
476 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
476 | plot().replot(QCustomPlot::rpQueuedReplot); | |
477 | } |
|
477 | } | |
478 |
|
478 | |||
479 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
479 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
480 | { |
|
480 | { | |
481 | if (visitor) { |
|
481 | if (visitor) { | |
482 | visitor->visit(this); |
|
482 | visitor->visit(this); | |
483 | } |
|
483 | } | |
484 | else { |
|
484 | else { | |
485 | qCCritical(LOG_VisualizationGraphWidget()) |
|
485 | qCCritical(LOG_VisualizationGraphWidget()) | |
486 | << tr("Can't visit widget : the visitor is null"); |
|
486 | << tr("Can't visit widget : the visitor is null"); | |
487 | } |
|
487 | } | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
490 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
491 | { |
|
491 | { | |
492 | auto isSpectrogram = [](const auto &variable) { |
|
492 | auto isSpectrogram = [](const auto &variable) { | |
493 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; |
|
493 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; | |
494 | }; |
|
494 | }; | |
495 |
|
495 | |||
496 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
496 | // - A spectrogram series can't be dropped on graph with existing plottables | |
497 | // - No data series can be dropped on graph with existing spectrogram series |
|
497 | // - No data series can be dropped on graph with existing spectrogram series | |
498 | return isSpectrogram(variable) |
|
498 | return isSpectrogram(variable) | |
499 | ? impl->m_VariableToPlotMultiMap.empty() |
|
499 | ? impl->m_VariableToPlotMultiMap.empty() | |
500 | : std::none_of( |
|
500 | : std::none_of( | |
501 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), |
|
501 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), | |
502 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); |
|
502 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
505 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
506 | { |
|
506 | { | |
507 | // Finds the variable among the keys of the map |
|
507 | // Finds the variable among the keys of the map | |
508 | auto variablePtr = &variable; |
|
508 | auto variablePtr = &variable; | |
509 | auto findVariable |
|
509 | auto findVariable | |
510 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
510 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
511 |
|
511 | |||
512 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
512 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
513 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
513 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
514 | return it != end; |
|
514 | return it != end; | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | QString VisualizationGraphWidget::name() const |
|
517 | QString VisualizationGraphWidget::name() const | |
518 | { |
|
518 | { | |
519 | return impl->m_Name; |
|
519 | return impl->m_Name; | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const |
|
522 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const | |
523 | { |
|
523 | { | |
524 | auto mimeData = new QMimeData; |
|
524 | auto mimeData = new QMimeData; | |
525 |
|
525 | |||
526 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); |
|
526 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); | |
527 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
527 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
528 | && selectionZoneItemUnderCursor) { |
|
528 | && selectionZoneItemUnderCursor) { | |
529 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( |
|
529 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( | |
530 | selectionZoneItemUnderCursor->range())); |
|
530 | selectionZoneItemUnderCursor->range())); | |
531 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( |
|
531 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( | |
532 | selectionZoneItemUnderCursor->range())); |
|
532 | selectionZoneItemUnderCursor->range())); | |
533 | } |
|
533 | } | |
534 | else { |
|
534 | else { | |
535 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); |
|
535 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); | |
536 |
|
536 | |||
537 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
537 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
538 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
538 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
541 | return mimeData; |
|
541 | return mimeData; | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) |
|
544 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) | |
545 | { |
|
545 | { | |
546 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); |
|
546 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); | |
547 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
547 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
548 | && selectionZoneItemUnderCursor) { |
|
548 | && selectionZoneItemUnderCursor) { | |
549 |
|
549 | |||
550 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
550 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
551 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
551 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
552 |
|
552 | |||
553 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
553 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
554 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} |
|
554 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} | |
555 | .toSize(); |
|
555 | .toSize(); | |
556 |
|
556 | |||
557 | auto pixmap = QPixmap(zoneSize); |
|
557 | auto pixmap = QPixmap(zoneSize); | |
558 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); |
|
558 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); | |
559 |
|
559 | |||
560 | return pixmap; |
|
560 | return pixmap; | |
561 | } |
|
561 | } | |
562 |
|
562 | |||
563 | return QPixmap(); |
|
563 | return QPixmap(); | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | bool VisualizationGraphWidget::isDragAllowed() const |
|
566 | bool VisualizationGraphWidget::isDragAllowed() const | |
567 | { |
|
567 | { | |
568 | return true; |
|
568 | return true; | |
569 | } |
|
569 | } | |
570 |
|
570 | |||
571 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
571 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
572 | { |
|
572 | { | |
573 | if (highlighted) { |
|
573 | if (highlighted) { | |
574 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
574 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
575 | } |
|
575 | } | |
576 | else { |
|
576 | else { | |
577 | plot().setBackground(QBrush(Qt::white)); |
|
577 | plot().setBackground(QBrush(Qt::white)); | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | plot().update(); |
|
580 | plot().update(); | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
583 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
584 | { |
|
584 | { | |
585 | impl->m_VerticalCursor->setPosition(time); |
|
585 | impl->m_VerticalCursor->setPosition(time); | |
586 | impl->m_VerticalCursor->setVisible(true); |
|
586 | impl->m_VerticalCursor->setVisible(true); | |
587 |
|
587 | |||
588 | auto text |
|
588 | auto text | |
589 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
589 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
590 | impl->m_VerticalCursor->setLabelText(text); |
|
590 | impl->m_VerticalCursor->setLabelText(text); | |
591 | } |
|
591 | } | |
592 |
|
592 | |||
593 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
593 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
594 | { |
|
594 | { | |
595 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
595 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
596 | impl->m_VerticalCursor->setVisible(true); |
|
596 | impl->m_VerticalCursor->setVisible(true); | |
597 |
|
597 | |||
598 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
598 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
599 | auto text |
|
599 | auto text | |
600 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
600 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
601 | impl->m_VerticalCursor->setLabelText(text); |
|
601 | impl->m_VerticalCursor->setLabelText(text); | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | void VisualizationGraphWidget::removeVerticalCursor() |
|
604 | void VisualizationGraphWidget::removeVerticalCursor() | |
605 | { |
|
605 | { | |
606 | impl->m_VerticalCursor->setVisible(false); |
|
606 | impl->m_VerticalCursor->setVisible(false); | |
607 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
607 | plot().replot(QCustomPlot::rpQueuedReplot); | |
608 | } |
|
608 | } | |
609 |
|
609 | |||
610 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
610 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
611 | { |
|
611 | { | |
612 | impl->m_HorizontalCursor->setPosition(value); |
|
612 | impl->m_HorizontalCursor->setPosition(value); | |
613 | impl->m_HorizontalCursor->setVisible(true); |
|
613 | impl->m_HorizontalCursor->setVisible(true); | |
614 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
614 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
617 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
618 | { |
|
618 | { | |
619 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
619 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
620 | impl->m_HorizontalCursor->setVisible(true); |
|
620 | impl->m_HorizontalCursor->setVisible(true); | |
621 |
|
621 | |||
622 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
622 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
623 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
623 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
624 | } |
|
624 | } | |
625 |
|
625 | |||
626 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
626 | void VisualizationGraphWidget::removeHorizontalCursor() | |
627 | { |
|
627 | { | |
628 | impl->m_HorizontalCursor->setVisible(false); |
|
628 | impl->m_HorizontalCursor->setVisible(false); | |
629 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
629 | plot().replot(QCustomPlot::rpQueuedReplot); | |
630 | } |
|
630 | } | |
631 |
|
631 | |||
632 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
632 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
633 | { |
|
633 | { | |
634 | Q_UNUSED(event); |
|
634 | Q_UNUSED(event); | |
635 |
|
635 | |||
|
636 | for (auto i : impl->m_SelectionZones) { | |||
|
637 | parentVisualizationWidget()->selectionZoneManager().setSelected(i, false); | |||
|
638 | } | |||
|
639 | ||||
636 | // Prevents that all variables will be removed from graph when it will be closed |
|
640 | // Prevents that all variables will be removed from graph when it will be closed | |
637 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
641 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
638 | emit variableAboutToBeRemoved(variableEntry.first); |
|
642 | emit variableAboutToBeRemoved(variableEntry.first); | |
639 | } |
|
643 | } | |
640 | } |
|
644 | } | |
641 |
|
645 | |||
642 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
646 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |
643 | { |
|
647 | { | |
644 | Q_UNUSED(event); |
|
648 | Q_UNUSED(event); | |
645 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
649 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
646 | } |
|
650 | } | |
647 |
|
651 | |||
648 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
652 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |
649 | { |
|
653 | { | |
650 | Q_UNUSED(event); |
|
654 | Q_UNUSED(event); | |
651 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
655 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
652 |
|
656 | |||
653 | if (auto parentZone = parentZoneWidget()) { |
|
657 | if (auto parentZone = parentZoneWidget()) { | |
654 | parentZone->notifyMouseLeaveGraph(this); |
|
658 | parentZone->notifyMouseLeaveGraph(this); | |
655 | } |
|
659 | } | |
656 | else { |
|
660 | else { | |
657 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
661 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
658 | } |
|
662 | } | |
659 |
|
663 | |||
660 | if (impl->m_HoveredZone) { |
|
664 | if (impl->m_HoveredZone) { | |
661 | impl->m_HoveredZone->setHovered(false); |
|
665 | impl->m_HoveredZone->setHovered(false); | |
662 | impl->m_HoveredZone = nullptr; |
|
666 | impl->m_HoveredZone = nullptr; | |
663 | } |
|
667 | } | |
664 | } |
|
668 | } | |
665 |
|
669 | |||
666 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept |
|
670 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept | |
667 | { |
|
671 | { | |
668 | return *ui->widget; |
|
672 | return *ui->widget; | |
669 | } |
|
673 | } | |
670 |
|
674 | |||
671 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
675 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
672 | { |
|
676 | { | |
673 | QMenu graphMenu{}; |
|
677 | QMenu graphMenu{}; | |
674 |
|
678 | |||
675 | // Iterates on variables (unique keys) |
|
679 | // Iterates on variables (unique keys) | |
676 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
680 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
677 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
681 | end = impl->m_VariableToPlotMultiMap.cend(); | |
678 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
682 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
679 | // 'Remove variable' action |
|
683 | // 'Remove variable' action | |
680 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
684 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
681 | [ this, var = it->first ]() { removeVariable(var); }); |
|
685 | [ this, var = it->first ]() { removeVariable(var); }); | |
682 | } |
|
686 | } | |
683 |
|
687 | |||
684 | if (!impl->m_ZoomStack.isEmpty()) { |
|
688 | if (!impl->m_ZoomStack.isEmpty()) { | |
685 | if (!graphMenu.isEmpty()) { |
|
689 | if (!graphMenu.isEmpty()) { | |
686 | graphMenu.addSeparator(); |
|
690 | graphMenu.addSeparator(); | |
687 | } |
|
691 | } | |
688 |
|
692 | |||
689 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
693 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
690 | } |
|
694 | } | |
691 |
|
695 | |||
692 | // Selection Zone Actions |
|
696 | // Selection Zone Actions | |
693 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
697 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
694 | if (selectionZoneItem) { |
|
698 | if (selectionZoneItem) { | |
695 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
699 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
696 | selectedItems.removeAll(selectionZoneItem); |
|
700 | selectedItems.removeAll(selectionZoneItem); | |
697 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
701 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
698 |
|
702 | |||
699 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
703 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
700 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { |
|
704 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { | |
701 | graphMenu.addSeparator(); |
|
705 | graphMenu.addSeparator(); | |
702 | } |
|
706 | } | |
703 |
|
707 | |||
704 | QHash<QString, QMenu *> subMenus; |
|
708 | QHash<QString, QMenu *> subMenus; | |
705 | QHash<QString, bool> subMenusEnabled; |
|
709 | QHash<QString, bool> subMenusEnabled; | |
706 |
|
710 | |||
707 | for (auto zoneAction : zoneActions) { |
|
711 | for (auto zoneAction : zoneActions) { | |
708 |
|
712 | |||
709 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
713 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
710 |
|
714 | |||
711 | auto menu = &graphMenu; |
|
715 | auto menu = &graphMenu; | |
712 | for (auto subMenuName : zoneAction->subMenuList()) { |
|
716 | for (auto subMenuName : zoneAction->subMenuList()) { | |
713 | if (!subMenus.contains(subMenuName)) { |
|
717 | if (!subMenus.contains(subMenuName)) { | |
714 | menu = menu->addMenu(subMenuName); |
|
718 | menu = menu->addMenu(subMenuName); | |
715 | subMenus[subMenuName] = menu; |
|
719 | subMenus[subMenuName] = menu; | |
716 | subMenusEnabled[subMenuName] = isEnabled; |
|
720 | subMenusEnabled[subMenuName] = isEnabled; | |
717 | } |
|
721 | } | |
718 | else { |
|
722 | else { | |
719 | menu = subMenus.value(subMenuName); |
|
723 | menu = subMenus.value(subMenuName); | |
720 | if (isEnabled) { |
|
724 | if (isEnabled) { | |
721 | // The sub menu is enabled if at least one of its actions is enabled |
|
725 | // The sub menu is enabled if at least one of its actions is enabled | |
722 | subMenusEnabled[subMenuName] = true; |
|
726 | subMenusEnabled[subMenuName] = true; | |
723 | } |
|
727 | } | |
724 | } |
|
728 | } | |
725 | } |
|
729 | } | |
726 |
|
730 | |||
727 | auto action = menu->addAction(zoneAction->name()); |
|
731 | auto action = menu->addAction(zoneAction->name()); | |
728 | action->setEnabled(isEnabled); |
|
732 | action->setEnabled(isEnabled); | |
729 | action->setShortcut(zoneAction->displayedShortcut()); |
|
733 | action->setShortcut(zoneAction->displayedShortcut()); | |
730 | QObject::connect(action, &QAction::triggered, |
|
734 | QObject::connect(action, &QAction::triggered, | |
731 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
735 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
732 | } |
|
736 | } | |
733 |
|
737 | |||
734 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { |
|
738 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |
735 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
739 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
736 | } |
|
740 | } | |
737 | } |
|
741 | } | |
738 |
|
742 | |||
739 | if (!graphMenu.isEmpty()) { |
|
743 | if (!graphMenu.isEmpty()) { | |
740 | graphMenu.exec(QCursor::pos()); |
|
744 | graphMenu.exec(QCursor::pos()); | |
741 | } |
|
745 | } | |
742 | } |
|
746 | } | |
743 |
|
747 | |||
744 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
748 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
745 | { |
|
749 | { | |
746 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
750 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
747 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
751 | << QThread::currentThread()->objectName() << "DoAcqui" | |
748 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); |
|
752 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); | |
749 |
|
753 | |||
750 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
754 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
751 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
755 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
752 |
|
756 | |||
753 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { |
|
757 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { | |
754 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
758 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
755 |
|
759 | |||
756 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
760 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
757 | end = impl->m_VariableToPlotMultiMap.end(); |
|
761 | end = impl->m_VariableToPlotMultiMap.end(); | |
758 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
762 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
759 | variableUnderGraphVector.push_back(it->first); |
|
763 | variableUnderGraphVector.push_back(it->first); | |
760 | } |
|
764 | } | |
761 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
765 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, | |
762 | !impl->m_IsCalibration); |
|
766 | !impl->m_IsCalibration); | |
763 | } |
|
767 | } | |
764 |
|
768 | |||
765 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { |
|
769 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { | |
766 | qCDebug(LOG_VisualizationGraphWidget()) |
|
770 | qCDebug(LOG_VisualizationGraphWidget()) | |
767 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
771 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
768 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
772 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
769 | emit synchronize(graphRange, oldGraphRange); |
|
773 | emit synchronize(graphRange, oldGraphRange); | |
770 | } |
|
774 | } | |
771 |
|
775 | |||
772 | auto pos = mapFromGlobal(QCursor::pos()); |
|
776 | auto pos = mapFromGlobal(QCursor::pos()); | |
773 | auto axisPos = impl->posToAxisPos(pos, plot()); |
|
777 | auto axisPos = impl->posToAxisPos(pos, plot()); | |
774 | if (auto parentZone = parentZoneWidget()) { |
|
778 | if (auto parentZone = parentZoneWidget()) { | |
775 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
779 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
776 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); |
|
780 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); | |
777 | } |
|
781 | } | |
778 | else { |
|
782 | else { | |
779 | parentZone->notifyMouseLeaveGraph(this); |
|
783 | parentZone->notifyMouseLeaveGraph(this); | |
780 | } |
|
784 | } | |
781 | } |
|
785 | } | |
782 | else { |
|
786 | else { | |
783 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
787 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
784 | } |
|
788 | } | |
785 |
|
789 | |||
786 | // Quits calibration |
|
790 | // Quits calibration | |
787 | impl->m_IsCalibration = false; |
|
791 | impl->m_IsCalibration = false; | |
788 | } |
|
792 | } | |
789 |
|
793 | |||
790 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept |
|
794 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept | |
791 | { |
|
795 | { | |
792 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
796 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
793 | } |
|
797 | } | |
794 |
|
798 | |||
795 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
799 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
796 | { |
|
800 | { | |
797 | // Handles plot rendering when mouse is moving |
|
801 | // Handles plot rendering when mouse is moving | |
798 | impl->m_RenderingDelegate->onMouseMove(event); |
|
802 | impl->m_RenderingDelegate->onMouseMove(event); | |
799 |
|
803 | |||
800 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
804 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); | |
801 |
|
805 | |||
802 | // Zoom box and zone drawing |
|
806 | // Zoom box and zone drawing | |
803 | if (impl->m_DrawingZoomRect) { |
|
807 | if (impl->m_DrawingZoomRect) { | |
804 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
808 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
805 | } |
|
809 | } | |
806 | else if (impl->m_DrawingZone) { |
|
810 | else if (impl->m_DrawingZone) { | |
807 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
811 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
808 | } |
|
812 | } | |
809 |
|
813 | |||
810 | // Cursor |
|
814 | // Cursor | |
811 | if (auto parentZone = parentZoneWidget()) { |
|
815 | if (auto parentZone = parentZoneWidget()) { | |
812 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
816 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
813 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
817 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
814 | } |
|
818 | } | |
815 | else { |
|
819 | else { | |
816 | parentZone->notifyMouseLeaveGraph(this); |
|
820 | parentZone->notifyMouseLeaveGraph(this); | |
817 | } |
|
821 | } | |
818 | } |
|
822 | } | |
819 | else { |
|
823 | else { | |
820 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
824 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
821 | } |
|
825 | } | |
822 |
|
826 | |||
823 | // Search for the selection zone under the mouse |
|
827 | // Search for the selection zone under the mouse | |
824 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
828 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
825 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
829 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
826 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { |
|
830 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
827 |
|
831 | |||
828 | // Sets the appropriate cursor shape |
|
832 | // Sets the appropriate cursor shape | |
829 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
833 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
830 | setCursor(cursorShape); |
|
834 | setCursor(cursorShape); | |
831 |
|
835 | |||
832 | // Manages the hovered zone |
|
836 | // Manages the hovered zone | |
833 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { |
|
837 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
834 | if (impl->m_HoveredZone) { |
|
838 | if (impl->m_HoveredZone) { | |
835 | impl->m_HoveredZone->setHovered(false); |
|
839 | impl->m_HoveredZone->setHovered(false); | |
836 | } |
|
840 | } | |
837 | selectionZoneItemUnderCursor->setHovered(true); |
|
841 | selectionZoneItemUnderCursor->setHovered(true); | |
838 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
842 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
839 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
843 | plot().replot(QCustomPlot::rpQueuedReplot); | |
840 | } |
|
844 | } | |
841 | } |
|
845 | } | |
842 | else { |
|
846 | else { | |
843 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
847 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
844 | if (impl->m_HoveredZone) { |
|
848 | if (impl->m_HoveredZone) { | |
845 | impl->m_HoveredZone->setHovered(false); |
|
849 | impl->m_HoveredZone->setHovered(false); | |
846 | impl->m_HoveredZone = nullptr; |
|
850 | impl->m_HoveredZone = nullptr; | |
847 | } |
|
851 | } | |
848 |
|
852 | |||
849 | setCursor(Qt::ArrowCursor); |
|
853 | setCursor(Qt::ArrowCursor); | |
850 | } |
|
854 | } | |
851 |
|
855 | |||
852 | impl->m_HasMovedMouse = true; |
|
856 | impl->m_HasMovedMouse = true; | |
853 | VisualizationDragWidget::mouseMoveEvent(event); |
|
857 | VisualizationDragWidget::mouseMoveEvent(event); | |
854 | } |
|
858 | } | |
855 |
|
859 | |||
856 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
860 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
857 | { |
|
861 | { | |
858 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
862 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
859 | if (value != 0) { |
|
863 | if (value != 0) { | |
860 |
|
864 | |||
861 | auto direction = value > 0 ? 1.0 : -1.0; |
|
865 | auto direction = value > 0 ? 1.0 : -1.0; | |
862 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
866 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
863 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
867 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
864 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
868 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
865 |
|
869 | |||
866 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
870 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
867 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
871 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
868 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
872 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
869 |
|
873 | |||
870 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
874 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
871 |
|
875 | |||
872 | if (!isZoomX && !isZoomY) { |
|
876 | if (!isZoomX && !isZoomY) { | |
873 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
877 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
874 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
878 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
875 |
|
879 | |||
876 | axis->setRange(axis->range() + diff); |
|
880 | axis->setRange(axis->range() + diff); | |
877 |
|
881 | |||
878 | if (plot().noAntialiasingOnDrag()) { |
|
882 | if (plot().noAntialiasingOnDrag()) { | |
879 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
883 | plot().setNotAntialiasedElements(QCP::aeAll); | |
880 | } |
|
884 | } | |
881 |
|
885 | |||
882 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
886 | plot().replot(QCustomPlot::rpQueuedReplot); | |
883 | } |
|
887 | } | |
884 | } |
|
888 | } | |
885 | } |
|
889 | } | |
886 |
|
890 | |||
887 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
891 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
888 | { |
|
892 | { | |
889 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
893 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
890 | auto isSelectionZoneMode |
|
894 | auto isSelectionZoneMode | |
891 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
895 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
892 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
896 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
893 |
|
897 | |||
894 | if (!isDragDropClick && isLeftClick) { |
|
898 | if (!isDragDropClick && isLeftClick) { | |
895 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
899 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { | |
896 | // Starts a zoom box |
|
900 | // Starts a zoom box | |
897 | impl->startDrawingRect(event->pos(), plot()); |
|
901 | impl->startDrawingRect(event->pos(), plot()); | |
898 | } |
|
902 | } | |
899 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { |
|
903 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { | |
900 | // Starts a new selection zone |
|
904 | // Starts a new selection zone | |
901 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); |
|
905 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); | |
902 | if (!zoneAtPos) { |
|
906 | if (!zoneAtPos) { | |
903 | impl->startDrawingZone(event->pos(), this); |
|
907 | impl->startDrawingZone(event->pos(), this); | |
904 | } |
|
908 | } | |
905 | } |
|
909 | } | |
906 | } |
|
910 | } | |
907 |
|
911 | |||
908 | // Allows mouse panning only in default mode |
|
912 | // Allows mouse panning only in default mode | |
909 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() |
|
913 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
910 | == SqpApplication::PlotsInteractionMode::None |
|
914 | == SqpApplication::PlotsInteractionMode::None | |
911 | && !isDragDropClick); |
|
915 | && !isDragDropClick); | |
912 |
|
916 | |||
913 | // Allows zone edition only in selection zone mode without drag&drop |
|
917 | // Allows zone edition only in selection zone mode without drag&drop | |
914 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
918 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
915 |
|
919 | |||
916 | // Selection / Deselection |
|
920 | // Selection / Deselection | |
917 | if (isSelectionZoneMode) { |
|
921 | if (isSelectionZoneMode) { | |
918 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
922 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
919 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
923 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
920 |
|
924 | |||
921 |
|
925 | |||
922 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
926 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
923 | && !isMultiSelectionClick) { |
|
927 | && !isMultiSelectionClick) { | |
924 | parentVisualizationWidget()->selectionZoneManager().select( |
|
928 | parentVisualizationWidget()->selectionZoneManager().select( | |
925 | {selectionZoneItemUnderCursor}); |
|
929 | {selectionZoneItemUnderCursor}); | |
926 | } |
|
930 | } | |
927 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { |
|
931 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { | |
928 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
932 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
929 | } |
|
933 | } | |
930 | else { |
|
934 | else { | |
931 | // No selection change |
|
935 | // No selection change | |
932 | } |
|
936 | } | |
933 |
|
937 | |||
934 | if (selectionZoneItemUnderCursor && isLeftClick) { |
|
938 | if (selectionZoneItemUnderCursor && isLeftClick) { | |
935 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
939 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
936 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
940 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
937 | } |
|
941 | } | |
938 | } |
|
942 | } | |
939 |
|
943 | |||
940 |
|
944 | |||
941 | impl->m_HasMovedMouse = false; |
|
945 | impl->m_HasMovedMouse = false; | |
942 | VisualizationDragWidget::mousePressEvent(event); |
|
946 | VisualizationDragWidget::mousePressEvent(event); | |
943 | } |
|
947 | } | |
944 |
|
948 | |||
945 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
949 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
946 | { |
|
950 | { | |
947 | if (impl->m_DrawingZoomRect) { |
|
951 | if (impl->m_DrawingZoomRect) { | |
948 |
|
952 | |||
949 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
953 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
950 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
954 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
951 |
|
955 | |||
952 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
956 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
953 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; |
|
957 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
954 |
|
958 | |||
955 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
959 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
956 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; |
|
960 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
957 |
|
961 | |||
958 | impl->removeDrawingRect(plot()); |
|
962 | impl->removeDrawingRect(plot()); | |
959 |
|
963 | |||
960 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
964 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
961 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { |
|
965 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { | |
962 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
966 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
963 | axisX->setRange(newAxisXRange); |
|
967 | axisX->setRange(newAxisXRange); | |
964 | axisY->setRange(newAxisYRange); |
|
968 | axisY->setRange(newAxisYRange); | |
965 |
|
969 | |||
966 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
970 | plot().replot(QCustomPlot::rpQueuedReplot); | |
967 | } |
|
971 | } | |
968 | } |
|
972 | } | |
969 |
|
973 | |||
970 | impl->endDrawingZone(this); |
|
974 | impl->endDrawingZone(this); | |
971 |
|
975 | |||
972 | // Selection / Deselection |
|
976 | // Selection / Deselection | |
973 | auto isSelectionZoneMode |
|
977 | auto isSelectionZoneMode | |
974 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
978 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
975 | if (isSelectionZoneMode) { |
|
979 | if (isSelectionZoneMode) { | |
976 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
980 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
977 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
981 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
978 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
982 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
979 | && !impl->m_HasMovedMouse) { |
|
983 | && !impl->m_HasMovedMouse) { | |
980 |
|
984 | |||
981 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
985 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
982 | if (zonesUnderCursor.count() > 1) { |
|
986 | if (zonesUnderCursor.count() > 1) { | |
983 | // There are multiple zones under the mouse. |
|
987 | // There are multiple zones under the mouse. | |
984 | // Performs the selection with a selection dialog. |
|
988 | // Performs the selection with a selection dialog. | |
985 | VisualizationMultiZoneSelectionDialog dialog{this}; |
|
989 | VisualizationMultiZoneSelectionDialog dialog{this}; | |
986 | dialog.setZones(zonesUnderCursor); |
|
990 | dialog.setZones(zonesUnderCursor); | |
987 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
991 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
988 | dialog.activateWindow(); |
|
992 | dialog.activateWindow(); | |
989 | dialog.raise(); |
|
993 | dialog.raise(); | |
990 | if (dialog.exec() == QDialog::Accepted) { |
|
994 | if (dialog.exec() == QDialog::Accepted) { | |
991 | auto selection = dialog.selectedZones(); |
|
995 | auto selection = dialog.selectedZones(); | |
992 |
|
996 | |||
993 | if (!isMultiSelectionClick) { |
|
997 | if (!isMultiSelectionClick) { | |
994 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
998 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
995 | } |
|
999 | } | |
996 |
|
1000 | |||
997 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { |
|
1001 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { | |
998 | auto zone = it.key(); |
|
1002 | auto zone = it.key(); | |
999 | auto isSelected = it.value(); |
|
1003 | auto isSelected = it.value(); | |
1000 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, |
|
1004 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, | |
1001 | isSelected); |
|
1005 | isSelected); | |
1002 |
|
1006 | |||
1003 | if (isSelected) { |
|
1007 | if (isSelected) { | |
1004 | // Puts the zone on top of the stack so it can be moved or resized |
|
1008 | // Puts the zone on top of the stack so it can be moved or resized | |
1005 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
1009 | impl->moveSelectionZoneOnTop(zone, plot()); | |
1006 | } |
|
1010 | } | |
1007 | } |
|
1011 | } | |
1008 | } |
|
1012 | } | |
1009 | } |
|
1013 | } | |
1010 | else { |
|
1014 | else { | |
1011 | if (!isMultiSelectionClick) { |
|
1015 | if (!isMultiSelectionClick) { | |
1012 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1016 | parentVisualizationWidget()->selectionZoneManager().select( | |
1013 | {selectionZoneItemUnderCursor}); |
|
1017 | {selectionZoneItemUnderCursor}); | |
1014 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
1018 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
1015 | } |
|
1019 | } | |
1016 | else { |
|
1020 | else { | |
1017 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
1021 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
1018 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
1022 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |
1019 | || event->button() == Qt::RightButton); |
|
1023 | || event->button() == Qt::RightButton); | |
1020 | } |
|
1024 | } | |
1021 | } |
|
1025 | } | |
1022 | } |
|
1026 | } | |
1023 | else { |
|
1027 | else { | |
1024 | // No selection change |
|
1028 | // No selection change | |
1025 | } |
|
1029 | } | |
1026 | } |
|
1030 | } | |
1027 | } |
|
1031 | } | |
1028 |
|
1032 | |||
1029 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
1033 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
1030 | { |
|
1034 | { | |
1031 | auto graphRange = ui->widget->xAxis->range(); |
|
1035 | auto graphRange = ui->widget->xAxis->range(); | |
1032 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
1036 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
1033 |
|
1037 | |||
1034 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
1038 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
1035 | auto variable = variableEntry.first; |
|
1039 | auto variable = variableEntry.first; | |
1036 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1040 | qCDebug(LOG_VisualizationGraphWidget()) | |
1037 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
1041 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
1038 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1042 | qCDebug(LOG_VisualizationGraphWidget()) | |
1039 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
1043 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
1040 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
1044 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
1041 | impl->updateData(variableEntry.second, variable, variable->range()); |
|
1045 | impl->updateData(variableEntry.second, variable, variable->range()); | |
1042 | } |
|
1046 | } | |
1043 | } |
|
1047 | } | |
1044 | } |
|
1048 | } | |
1045 |
|
1049 | |||
1046 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
1050 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
1047 | const SqpRange &range) |
|
1051 | const SqpRange &range) | |
1048 | { |
|
1052 | { | |
1049 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
1053 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1050 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1054 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
1051 | impl->updateData(it->second, variable, range); |
|
1055 | impl->updateData(it->second, variable, range); | |
1052 | } |
|
1056 | } | |
1053 | } |
|
1057 | } |
General Comments 0
You need to be logged in to leave comments.
Login now