@@ -1,1055 +1,1054 | |||||
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 | #ifdef Q_OS_MAC |
|
261 | #ifdef Q_OS_MAC | |
262 | plot().setPlottingHint(QCP::phFastPolylines, true); |
|
262 | plot().setPlottingHint(QCP::phFastPolylines, true); | |
263 | #endif |
|
263 | #endif | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 |
|
266 | |||
267 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
267 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
268 | { |
|
268 | { | |
269 | delete ui; |
|
269 | delete ui; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
272 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
273 | { |
|
273 | { | |
274 | auto parent = parentWidget(); |
|
274 | auto parent = parentWidget(); | |
275 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
275 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { | |
276 | parent = parent->parentWidget(); |
|
276 | parent = parent->parentWidget(); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
279 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const |
|
282 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const | |
283 | { |
|
283 | { | |
284 | auto parent = parentWidget(); |
|
284 | auto parent = parentWidget(); | |
285 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { |
|
285 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { | |
286 | parent = parent->parentWidget(); |
|
286 | parent = parent->parentWidget(); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | return qobject_cast<VisualizationWidget *>(parent); |
|
289 | return qobject_cast<VisualizationWidget *>(parent); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void VisualizationGraphWidget::setFlags(GraphFlags flags) |
|
292 | void VisualizationGraphWidget::setFlags(GraphFlags flags) | |
293 | { |
|
293 | { | |
294 | impl->m_Flags = std::move(flags); |
|
294 | impl->m_Flags = std::move(flags); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
297 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
298 | { |
|
298 | { | |
299 | /// Lambda used to set graph's units and range according to the variable passed in parameter |
|
299 | /// Lambda used to set graph's units and range according to the variable passed in parameter | |
300 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { |
|
300 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { | |
301 | impl->m_RenderingDelegate->setAxesUnits(*variable); |
|
301 | impl->m_RenderingDelegate->setAxesUnits(*variable); | |
302 |
|
302 | |||
303 | this->setFlags(GraphFlag::DisableAll); |
|
303 | this->setFlags(GraphFlag::DisableAll); | |
304 | setGraphRange(range); |
|
304 | setGraphRange(range); | |
305 | this->setFlags(GraphFlag::EnableAll); |
|
305 | this->setFlags(GraphFlag::EnableAll); | |
306 |
|
||||
307 | emit requestDataLoading({variable}, range, false); |
|
306 | emit requestDataLoading({variable}, range, false); | |
308 | }; |
|
307 | }; | |
309 |
|
308 | |||
310 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
309 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
311 |
|
310 | |||
312 | // Calls update of graph's range and units when the data of the variable have been initialized. |
|
311 | // Calls update of graph's range and units when the data of the variable have been initialized. | |
313 | // Note: we use QueuedConnection here as the update event must be called in the UI thread |
|
312 | // Note: we use QueuedConnection here as the update event must be called in the UI thread | |
314 | connect(variable.get(), &Variable::dataInitialized, this, |
|
313 | connect(variable.get(), &Variable::dataInitialized, this, | |
315 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { |
|
314 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { | |
316 | if (auto var = varW.lock()) { |
|
315 | if (auto var = varW.lock()) { | |
317 | // If the variable is the first added in the graph, we load its range |
|
316 | // If the variable is the first added in the graph, we load its range | |
318 | auto firstVariableInGraph = range == INVALID_RANGE; |
|
317 | auto firstVariableInGraph = range == INVALID_RANGE; | |
319 | auto loadedRange = graphRange(); |
|
318 | auto loadedRange = graphRange(); | |
320 | if (impl->m_VariableAutoRangeOnInit) { |
|
319 | if (impl->m_VariableAutoRangeOnInit) { | |
321 | loadedRange = firstVariableInGraph ? var->range() : range; |
|
320 | loadedRange = firstVariableInGraph ? var->range() : range; | |
322 | } |
|
321 | } | |
323 | loadRange(var, loadedRange); |
|
322 | loadRange(var, loadedRange); | |
324 | setYRange(var); |
|
323 | setYRange(var); | |
325 | } |
|
324 | } | |
326 | }, |
|
325 | }, | |
327 | Qt::QueuedConnection); |
|
326 | Qt::QueuedConnection); | |
328 |
|
327 | |||
329 | // Uses delegate to create the qcpplot components according to the variable |
|
328 | // Uses delegate to create the qcpplot components according to the variable | |
330 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
329 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
331 |
|
330 | |||
332 | // Sets graph properties |
|
331 | // Sets graph properties | |
333 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); |
|
332 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); | |
334 |
|
333 | |||
335 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
334 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
336 |
|
335 | |||
337 | // If the variable already has its data loaded, load its units and its range in the graph |
|
336 | // If the variable already has its data loaded, load its units and its range in the graph | |
338 | if (variable->dataSeries() != nullptr) { |
|
337 | if (variable->dataSeries() != nullptr) { | |
339 | loadRange(variable, range); |
|
338 | loadRange(variable, range); | |
340 | } |
|
339 | } | |
341 |
|
340 | |||
342 | emit variableAdded(variable); |
|
341 | emit variableAdded(variable); | |
343 | } |
|
342 | } | |
344 |
|
343 | |||
345 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
344 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
346 | { |
|
345 | { | |
347 | // Each component associated to the variable : |
|
346 | // Each component associated to the variable : | |
348 | // - is removed from qcpplot (which deletes it) |
|
347 | // - is removed from qcpplot (which deletes it) | |
349 | // - is no longer referenced in the map |
|
348 | // - is no longer referenced in the map | |
350 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
349 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
351 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
350 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
352 | emit variableAboutToBeRemoved(variable); |
|
351 | emit variableAboutToBeRemoved(variable); | |
353 |
|
352 | |||
354 | auto &plottablesMap = variableIt->second; |
|
353 | auto &plottablesMap = variableIt->second; | |
355 |
|
354 | |||
356 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
355 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
357 | plottableIt != plottableEnd;) { |
|
356 | plottableIt != plottableEnd;) { | |
358 | ui->widget->removePlottable(plottableIt->second); |
|
357 | ui->widget->removePlottable(plottableIt->second); | |
359 | plottableIt = plottablesMap.erase(plottableIt); |
|
358 | plottableIt = plottablesMap.erase(plottableIt); | |
360 | } |
|
359 | } | |
361 |
|
360 | |||
362 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
361 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
363 | } |
|
362 | } | |
364 |
|
363 | |||
365 | // Updates graph |
|
364 | // Updates graph | |
366 | ui->widget->replot(); |
|
365 | ui->widget->replot(); | |
367 | } |
|
366 | } | |
368 |
|
367 | |||
369 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
368 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
370 | { |
|
369 | { | |
371 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
370 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
372 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
371 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
373 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
372 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
374 | variables << it->first; |
|
373 | variables << it->first; | |
375 | } |
|
374 | } | |
376 |
|
375 | |||
377 | return variables; |
|
376 | return variables; | |
378 | } |
|
377 | } | |
379 |
|
378 | |||
380 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) |
|
379 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
381 | { |
|
380 | { | |
382 | if (!variable) { |
|
381 | if (!variable) { | |
383 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
382 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
384 | return; |
|
383 | return; | |
385 | } |
|
384 | } | |
386 |
|
385 | |||
387 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); |
|
386 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |
388 | } |
|
387 | } | |
389 |
|
388 | |||
390 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
389 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
391 | { |
|
390 | { | |
392 | auto graphRange = ui->widget->xAxis->range(); |
|
391 | auto graphRange = ui->widget->xAxis->range(); | |
393 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
392 | return SqpRange{graphRange.lower, graphRange.upper}; | |
394 | } |
|
393 | } | |
395 |
|
394 | |||
396 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) |
|
395 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) | |
397 | { |
|
396 | { | |
398 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
397 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
399 |
|
398 | |||
400 | if (calibration) { |
|
399 | if (calibration) { | |
401 | impl->m_IsCalibration = true; |
|
400 | impl->m_IsCalibration = true; | |
402 | } |
|
401 | } | |
403 |
|
402 | |||
404 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
403 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
405 | ui->widget->replot(); |
|
404 | ui->widget->replot(); | |
406 |
|
405 | |||
407 | if (calibration) { |
|
406 | if (calibration) { | |
408 | impl->m_IsCalibration = false; |
|
407 | impl->m_IsCalibration = false; | |
409 | } |
|
408 | } | |
410 |
|
409 | |||
411 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
410 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
412 | } |
|
411 | } | |
413 |
|
412 | |||
414 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) |
|
413 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) | |
415 | { |
|
414 | { | |
416 | impl->m_VariableAutoRangeOnInit = value; |
|
415 | impl->m_VariableAutoRangeOnInit = value; | |
417 | } |
|
416 | } | |
418 |
|
417 | |||
419 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
418 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const | |
420 | { |
|
419 | { | |
421 | QVector<SqpRange> ranges; |
|
420 | QVector<SqpRange> ranges; | |
422 | for (auto zone : impl->m_SelectionZones) { |
|
421 | for (auto zone : impl->m_SelectionZones) { | |
423 | ranges << zone->range(); |
|
422 | ranges << zone->range(); | |
424 | } |
|
423 | } | |
425 |
|
424 | |||
426 | return ranges; |
|
425 | return ranges; | |
427 | } |
|
426 | } | |
428 |
|
427 | |||
429 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) |
|
428 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) | |
430 | { |
|
429 | { | |
431 | for (const auto &range : ranges) { |
|
430 | for (const auto &range : ranges) { | |
432 | // note: ownership is transfered to QCustomPlot |
|
431 | // note: ownership is transfered to QCustomPlot | |
433 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
432 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
434 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
433 | zone->setRange(range.m_TStart, range.m_TEnd); | |
435 | impl->addSelectionZone(zone); |
|
434 | impl->addSelectionZone(zone); | |
436 | } |
|
435 | } | |
437 |
|
436 | |||
438 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
437 | plot().replot(QCustomPlot::rpQueuedReplot); | |
439 | } |
|
438 | } | |
440 |
|
439 | |||
441 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, |
|
440 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, | |
442 | const SqpRange &range) |
|
441 | const SqpRange &range) | |
443 | { |
|
442 | { | |
444 | // note: ownership is transfered to QCustomPlot |
|
443 | // note: ownership is transfered to QCustomPlot | |
445 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
444 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
446 | zone->setName(name); |
|
445 | zone->setName(name); | |
447 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
446 | zone->setRange(range.m_TStart, range.m_TEnd); | |
448 | impl->addSelectionZone(zone); |
|
447 | impl->addSelectionZone(zone); | |
449 |
|
448 | |||
450 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
449 | plot().replot(QCustomPlot::rpQueuedReplot); | |
451 |
|
450 | |||
452 | return zone; |
|
451 | return zone; | |
453 | } |
|
452 | } | |
454 |
|
453 | |||
455 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) |
|
454 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) | |
456 | { |
|
455 | { | |
457 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
456 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
458 |
|
457 | |||
459 | if (impl->m_HoveredZone == selectionZone) { |
|
458 | if (impl->m_HoveredZone == selectionZone) { | |
460 | impl->m_HoveredZone = nullptr; |
|
459 | impl->m_HoveredZone = nullptr; | |
461 | setCursor(Qt::ArrowCursor); |
|
460 | setCursor(Qt::ArrowCursor); | |
462 | } |
|
461 | } | |
463 |
|
462 | |||
464 | impl->m_SelectionZones.removeAll(selectionZone); |
|
463 | impl->m_SelectionZones.removeAll(selectionZone); | |
465 | plot().removeItem(selectionZone); |
|
464 | plot().removeItem(selectionZone); | |
466 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
465 | plot().replot(QCustomPlot::rpQueuedReplot); | |
467 | } |
|
466 | } | |
468 |
|
467 | |||
469 | void VisualizationGraphWidget::undoZoom() |
|
468 | void VisualizationGraphWidget::undoZoom() | |
470 | { |
|
469 | { | |
471 | auto zoom = impl->m_ZoomStack.pop(); |
|
470 | auto zoom = impl->m_ZoomStack.pop(); | |
472 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
471 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
473 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
472 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
474 |
|
473 | |||
475 | axisX->setRange(zoom.first); |
|
474 | axisX->setRange(zoom.first); | |
476 | axisY->setRange(zoom.second); |
|
475 | axisY->setRange(zoom.second); | |
477 |
|
476 | |||
478 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
477 | plot().replot(QCustomPlot::rpQueuedReplot); | |
479 | } |
|
478 | } | |
480 |
|
479 | |||
481 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
480 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
482 | { |
|
481 | { | |
483 | if (visitor) { |
|
482 | if (visitor) { | |
484 | visitor->visit(this); |
|
483 | visitor->visit(this); | |
485 | } |
|
484 | } | |
486 | else { |
|
485 | else { | |
487 | qCCritical(LOG_VisualizationGraphWidget()) |
|
486 | qCCritical(LOG_VisualizationGraphWidget()) | |
488 | << tr("Can't visit widget : the visitor is null"); |
|
487 | << tr("Can't visit widget : the visitor is null"); | |
489 | } |
|
488 | } | |
490 | } |
|
489 | } | |
491 |
|
490 | |||
492 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
491 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
493 | { |
|
492 | { | |
494 | auto isSpectrogram = [](const auto &variable) { |
|
493 | auto isSpectrogram = [](const auto &variable) { | |
495 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; |
|
494 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; | |
496 | }; |
|
495 | }; | |
497 |
|
496 | |||
498 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
497 | // - A spectrogram series can't be dropped on graph with existing plottables | |
499 | // - No data series can be dropped on graph with existing spectrogram series |
|
498 | // - No data series can be dropped on graph with existing spectrogram series | |
500 | return isSpectrogram(variable) |
|
499 | return isSpectrogram(variable) | |
501 | ? impl->m_VariableToPlotMultiMap.empty() |
|
500 | ? impl->m_VariableToPlotMultiMap.empty() | |
502 | : std::none_of( |
|
501 | : std::none_of( | |
503 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), |
|
502 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), | |
504 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); |
|
503 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); | |
505 | } |
|
504 | } | |
506 |
|
505 | |||
507 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
506 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
508 | { |
|
507 | { | |
509 | // Finds the variable among the keys of the map |
|
508 | // Finds the variable among the keys of the map | |
510 | auto variablePtr = &variable; |
|
509 | auto variablePtr = &variable; | |
511 | auto findVariable |
|
510 | auto findVariable | |
512 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
511 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
513 |
|
512 | |||
514 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
513 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
515 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
514 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
516 | return it != end; |
|
515 | return it != end; | |
517 | } |
|
516 | } | |
518 |
|
517 | |||
519 | QString VisualizationGraphWidget::name() const |
|
518 | QString VisualizationGraphWidget::name() const | |
520 | { |
|
519 | { | |
521 | return impl->m_Name; |
|
520 | return impl->m_Name; | |
522 | } |
|
521 | } | |
523 |
|
522 | |||
524 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const |
|
523 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const | |
525 | { |
|
524 | { | |
526 | auto mimeData = new QMimeData; |
|
525 | auto mimeData = new QMimeData; | |
527 |
|
526 | |||
528 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); |
|
527 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); | |
529 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
528 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
530 | && selectionZoneItemUnderCursor) { |
|
529 | && selectionZoneItemUnderCursor) { | |
531 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( |
|
530 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( | |
532 | selectionZoneItemUnderCursor->range())); |
|
531 | selectionZoneItemUnderCursor->range())); | |
533 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( |
|
532 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( | |
534 | selectionZoneItemUnderCursor->range())); |
|
533 | selectionZoneItemUnderCursor->range())); | |
535 | } |
|
534 | } | |
536 | else { |
|
535 | else { | |
537 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); |
|
536 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); | |
538 |
|
537 | |||
539 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
538 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
540 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
539 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
541 | } |
|
540 | } | |
542 |
|
541 | |||
543 | return mimeData; |
|
542 | return mimeData; | |
544 | } |
|
543 | } | |
545 |
|
544 | |||
546 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) |
|
545 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) | |
547 | { |
|
546 | { | |
548 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); |
|
547 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); | |
549 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
548 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
550 | && selectionZoneItemUnderCursor) { |
|
549 | && selectionZoneItemUnderCursor) { | |
551 |
|
550 | |||
552 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
551 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
553 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
552 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
554 |
|
553 | |||
555 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
554 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
556 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} |
|
555 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} | |
557 | .toSize(); |
|
556 | .toSize(); | |
558 |
|
557 | |||
559 | auto pixmap = QPixmap(zoneSize); |
|
558 | auto pixmap = QPixmap(zoneSize); | |
560 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); |
|
559 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); | |
561 |
|
560 | |||
562 | return pixmap; |
|
561 | return pixmap; | |
563 | } |
|
562 | } | |
564 |
|
563 | |||
565 | return QPixmap(); |
|
564 | return QPixmap(); | |
566 | } |
|
565 | } | |
567 |
|
566 | |||
568 | bool VisualizationGraphWidget::isDragAllowed() const |
|
567 | bool VisualizationGraphWidget::isDragAllowed() const | |
569 | { |
|
568 | { | |
570 | return true; |
|
569 | return true; | |
571 | } |
|
570 | } | |
572 |
|
571 | |||
573 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
572 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
574 | { |
|
573 | { | |
575 | if (highlighted) { |
|
574 | if (highlighted) { | |
576 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
575 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
577 | } |
|
576 | } | |
578 | else { |
|
577 | else { | |
579 | plot().setBackground(QBrush(Qt::white)); |
|
578 | plot().setBackground(QBrush(Qt::white)); | |
580 | } |
|
579 | } | |
581 |
|
580 | |||
582 | plot().update(); |
|
581 | plot().update(); | |
583 | } |
|
582 | } | |
584 |
|
583 | |||
585 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
584 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
586 | { |
|
585 | { | |
587 | impl->m_VerticalCursor->setPosition(time); |
|
586 | impl->m_VerticalCursor->setPosition(time); | |
588 | impl->m_VerticalCursor->setVisible(true); |
|
587 | impl->m_VerticalCursor->setVisible(true); | |
589 |
|
588 | |||
590 | auto text |
|
589 | auto text | |
591 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
590 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
592 | impl->m_VerticalCursor->setLabelText(text); |
|
591 | impl->m_VerticalCursor->setLabelText(text); | |
593 | } |
|
592 | } | |
594 |
|
593 | |||
595 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
594 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
596 | { |
|
595 | { | |
597 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
596 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
598 | impl->m_VerticalCursor->setVisible(true); |
|
597 | impl->m_VerticalCursor->setVisible(true); | |
599 |
|
598 | |||
600 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
599 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
601 | auto text |
|
600 | auto text | |
602 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
601 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
603 | impl->m_VerticalCursor->setLabelText(text); |
|
602 | impl->m_VerticalCursor->setLabelText(text); | |
604 | } |
|
603 | } | |
605 |
|
604 | |||
606 | void VisualizationGraphWidget::removeVerticalCursor() |
|
605 | void VisualizationGraphWidget::removeVerticalCursor() | |
607 | { |
|
606 | { | |
608 | impl->m_VerticalCursor->setVisible(false); |
|
607 | impl->m_VerticalCursor->setVisible(false); | |
609 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
608 | plot().replot(QCustomPlot::rpQueuedReplot); | |
610 | } |
|
609 | } | |
611 |
|
610 | |||
612 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
611 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
613 | { |
|
612 | { | |
614 | impl->m_HorizontalCursor->setPosition(value); |
|
613 | impl->m_HorizontalCursor->setPosition(value); | |
615 | impl->m_HorizontalCursor->setVisible(true); |
|
614 | impl->m_HorizontalCursor->setVisible(true); | |
616 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
615 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
617 | } |
|
616 | } | |
618 |
|
617 | |||
619 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
618 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
620 | { |
|
619 | { | |
621 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
620 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
622 | impl->m_HorizontalCursor->setVisible(true); |
|
621 | impl->m_HorizontalCursor->setVisible(true); | |
623 |
|
622 | |||
624 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
623 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
625 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
624 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
626 | } |
|
625 | } | |
627 |
|
626 | |||
628 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
627 | void VisualizationGraphWidget::removeHorizontalCursor() | |
629 | { |
|
628 | { | |
630 | impl->m_HorizontalCursor->setVisible(false); |
|
629 | impl->m_HorizontalCursor->setVisible(false); | |
631 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
630 | plot().replot(QCustomPlot::rpQueuedReplot); | |
632 | } |
|
631 | } | |
633 |
|
632 | |||
634 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
633 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
635 | { |
|
634 | { | |
636 | Q_UNUSED(event); |
|
635 | Q_UNUSED(event); | |
637 |
|
636 | |||
638 | // Prevents that all variables will be removed from graph when it will be closed |
|
637 | // Prevents that all variables will be removed from graph when it will be closed | |
639 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
638 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
640 | emit variableAboutToBeRemoved(variableEntry.first); |
|
639 | emit variableAboutToBeRemoved(variableEntry.first); | |
641 | } |
|
640 | } | |
642 | } |
|
641 | } | |
643 |
|
642 | |||
644 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
643 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |
645 | { |
|
644 | { | |
646 | Q_UNUSED(event); |
|
645 | Q_UNUSED(event); | |
647 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
646 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
648 | } |
|
647 | } | |
649 |
|
648 | |||
650 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
649 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |
651 | { |
|
650 | { | |
652 | Q_UNUSED(event); |
|
651 | Q_UNUSED(event); | |
653 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
652 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
654 |
|
653 | |||
655 | if (auto parentZone = parentZoneWidget()) { |
|
654 | if (auto parentZone = parentZoneWidget()) { | |
656 | parentZone->notifyMouseLeaveGraph(this); |
|
655 | parentZone->notifyMouseLeaveGraph(this); | |
657 | } |
|
656 | } | |
658 | else { |
|
657 | else { | |
659 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
658 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
660 | } |
|
659 | } | |
661 |
|
660 | |||
662 | if (impl->m_HoveredZone) { |
|
661 | if (impl->m_HoveredZone) { | |
663 | impl->m_HoveredZone->setHovered(false); |
|
662 | impl->m_HoveredZone->setHovered(false); | |
664 | impl->m_HoveredZone = nullptr; |
|
663 | impl->m_HoveredZone = nullptr; | |
665 | } |
|
664 | } | |
666 | } |
|
665 | } | |
667 |
|
666 | |||
668 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept |
|
667 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept | |
669 | { |
|
668 | { | |
670 | return *ui->widget; |
|
669 | return *ui->widget; | |
671 | } |
|
670 | } | |
672 |
|
671 | |||
673 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
672 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
674 | { |
|
673 | { | |
675 | QMenu graphMenu{}; |
|
674 | QMenu graphMenu{}; | |
676 |
|
675 | |||
677 | // Iterates on variables (unique keys) |
|
676 | // Iterates on variables (unique keys) | |
678 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
677 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
679 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
678 | end = impl->m_VariableToPlotMultiMap.cend(); | |
680 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
679 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
681 | // 'Remove variable' action |
|
680 | // 'Remove variable' action | |
682 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
681 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
683 | [ this, var = it->first ]() { removeVariable(var); }); |
|
682 | [ this, var = it->first ]() { removeVariable(var); }); | |
684 | } |
|
683 | } | |
685 |
|
684 | |||
686 | if (!impl->m_ZoomStack.isEmpty()) { |
|
685 | if (!impl->m_ZoomStack.isEmpty()) { | |
687 | if (!graphMenu.isEmpty()) { |
|
686 | if (!graphMenu.isEmpty()) { | |
688 | graphMenu.addSeparator(); |
|
687 | graphMenu.addSeparator(); | |
689 | } |
|
688 | } | |
690 |
|
689 | |||
691 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
690 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
692 | } |
|
691 | } | |
693 |
|
692 | |||
694 | // Selection Zone Actions |
|
693 | // Selection Zone Actions | |
695 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
694 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
696 | if (selectionZoneItem) { |
|
695 | if (selectionZoneItem) { | |
697 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
696 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
698 | selectedItems.removeAll(selectionZoneItem); |
|
697 | selectedItems.removeAll(selectionZoneItem); | |
699 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
698 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
700 |
|
699 | |||
701 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
700 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
702 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { |
|
701 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { | |
703 | graphMenu.addSeparator(); |
|
702 | graphMenu.addSeparator(); | |
704 | } |
|
703 | } | |
705 |
|
704 | |||
706 | QHash<QString, QMenu *> subMenus; |
|
705 | QHash<QString, QMenu *> subMenus; | |
707 | QHash<QString, bool> subMenusEnabled; |
|
706 | QHash<QString, bool> subMenusEnabled; | |
708 |
|
707 | |||
709 | for (auto zoneAction : zoneActions) { |
|
708 | for (auto zoneAction : zoneActions) { | |
710 |
|
709 | |||
711 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
710 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
712 |
|
711 | |||
713 | auto menu = &graphMenu; |
|
712 | auto menu = &graphMenu; | |
714 | for (auto subMenuName : zoneAction->subMenuList()) { |
|
713 | for (auto subMenuName : zoneAction->subMenuList()) { | |
715 | if (!subMenus.contains(subMenuName)) { |
|
714 | if (!subMenus.contains(subMenuName)) { | |
716 | menu = menu->addMenu(subMenuName); |
|
715 | menu = menu->addMenu(subMenuName); | |
717 | subMenus[subMenuName] = menu; |
|
716 | subMenus[subMenuName] = menu; | |
718 | subMenusEnabled[subMenuName] = isEnabled; |
|
717 | subMenusEnabled[subMenuName] = isEnabled; | |
719 | } |
|
718 | } | |
720 | else { |
|
719 | else { | |
721 | menu = subMenus.value(subMenuName); |
|
720 | menu = subMenus.value(subMenuName); | |
722 | if (isEnabled) { |
|
721 | if (isEnabled) { | |
723 | // The sub menu is enabled if at least one of its actions is enabled |
|
722 | // The sub menu is enabled if at least one of its actions is enabled | |
724 | subMenusEnabled[subMenuName] = true; |
|
723 | subMenusEnabled[subMenuName] = true; | |
725 | } |
|
724 | } | |
726 | } |
|
725 | } | |
727 | } |
|
726 | } | |
728 |
|
727 | |||
729 | auto action = menu->addAction(zoneAction->name()); |
|
728 | auto action = menu->addAction(zoneAction->name()); | |
730 | action->setEnabled(isEnabled); |
|
729 | action->setEnabled(isEnabled); | |
731 | action->setShortcut(zoneAction->displayedShortcut()); |
|
730 | action->setShortcut(zoneAction->displayedShortcut()); | |
732 | QObject::connect(action, &QAction::triggered, |
|
731 | QObject::connect(action, &QAction::triggered, | |
733 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
732 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
734 | } |
|
733 | } | |
735 |
|
734 | |||
736 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { |
|
735 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |
737 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
736 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
738 | } |
|
737 | } | |
739 | } |
|
738 | } | |
740 |
|
739 | |||
741 | if (!graphMenu.isEmpty()) { |
|
740 | if (!graphMenu.isEmpty()) { | |
742 | graphMenu.exec(QCursor::pos()); |
|
741 | graphMenu.exec(QCursor::pos()); | |
743 | } |
|
742 | } | |
744 | } |
|
743 | } | |
745 |
|
744 | |||
746 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
745 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
747 | { |
|
746 | { | |
748 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
747 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
749 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
748 | << QThread::currentThread()->objectName() << "DoAcqui" | |
750 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); |
|
749 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); | |
751 |
|
750 | |||
752 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
751 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
753 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
752 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
754 |
|
753 | |||
755 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { |
|
754 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { | |
756 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
755 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
757 |
|
756 | |||
758 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
757 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
759 | end = impl->m_VariableToPlotMultiMap.end(); |
|
758 | end = impl->m_VariableToPlotMultiMap.end(); | |
760 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
759 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
761 | variableUnderGraphVector.push_back(it->first); |
|
760 | variableUnderGraphVector.push_back(it->first); | |
762 | } |
|
761 | } | |
763 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
762 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, | |
764 | !impl->m_IsCalibration); |
|
763 | !impl->m_IsCalibration); | |
765 | } |
|
764 | } | |
766 |
|
765 | |||
767 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { |
|
766 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { | |
768 | qCDebug(LOG_VisualizationGraphWidget()) |
|
767 | qCDebug(LOG_VisualizationGraphWidget()) | |
769 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
768 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
770 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
769 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
771 | emit synchronize(graphRange, oldGraphRange); |
|
770 | emit synchronize(graphRange, oldGraphRange); | |
772 | } |
|
771 | } | |
773 |
|
772 | |||
774 | auto pos = mapFromGlobal(QCursor::pos()); |
|
773 | auto pos = mapFromGlobal(QCursor::pos()); | |
775 | auto axisPos = impl->posToAxisPos(pos, plot()); |
|
774 | auto axisPos = impl->posToAxisPos(pos, plot()); | |
776 | if (auto parentZone = parentZoneWidget()) { |
|
775 | if (auto parentZone = parentZoneWidget()) { | |
777 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
776 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
778 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); |
|
777 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); | |
779 | } |
|
778 | } | |
780 | else { |
|
779 | else { | |
781 | parentZone->notifyMouseLeaveGraph(this); |
|
780 | parentZone->notifyMouseLeaveGraph(this); | |
782 | } |
|
781 | } | |
783 | } |
|
782 | } | |
784 | else { |
|
783 | else { | |
785 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
784 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
786 | } |
|
785 | } | |
787 |
|
786 | |||
788 | // Quits calibration |
|
787 | // Quits calibration | |
789 | impl->m_IsCalibration = false; |
|
788 | impl->m_IsCalibration = false; | |
790 | } |
|
789 | } | |
791 |
|
790 | |||
792 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept |
|
791 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept | |
793 | { |
|
792 | { | |
794 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
793 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
795 | } |
|
794 | } | |
796 |
|
795 | |||
797 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
796 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
798 | { |
|
797 | { | |
799 | // Handles plot rendering when mouse is moving |
|
798 | // Handles plot rendering when mouse is moving | |
800 | impl->m_RenderingDelegate->onMouseMove(event); |
|
799 | impl->m_RenderingDelegate->onMouseMove(event); | |
801 |
|
800 | |||
802 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
801 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); | |
803 |
|
802 | |||
804 | // Zoom box and zone drawing |
|
803 | // Zoom box and zone drawing | |
805 | if (impl->m_DrawingZoomRect) { |
|
804 | if (impl->m_DrawingZoomRect) { | |
806 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
805 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
807 | } |
|
806 | } | |
808 | else if (impl->m_DrawingZone) { |
|
807 | else if (impl->m_DrawingZone) { | |
809 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
808 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
810 | } |
|
809 | } | |
811 |
|
810 | |||
812 | // Cursor |
|
811 | // Cursor | |
813 | if (auto parentZone = parentZoneWidget()) { |
|
812 | if (auto parentZone = parentZoneWidget()) { | |
814 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
813 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
815 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
814 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
816 | } |
|
815 | } | |
817 | else { |
|
816 | else { | |
818 | parentZone->notifyMouseLeaveGraph(this); |
|
817 | parentZone->notifyMouseLeaveGraph(this); | |
819 | } |
|
818 | } | |
820 | } |
|
819 | } | |
821 | else { |
|
820 | else { | |
822 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
821 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
823 | } |
|
822 | } | |
824 |
|
823 | |||
825 | // Search for the selection zone under the mouse |
|
824 | // Search for the selection zone under the mouse | |
826 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
825 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
827 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
826 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
828 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { |
|
827 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
829 |
|
828 | |||
830 | // Sets the appropriate cursor shape |
|
829 | // Sets the appropriate cursor shape | |
831 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
830 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
832 | setCursor(cursorShape); |
|
831 | setCursor(cursorShape); | |
833 |
|
832 | |||
834 | // Manages the hovered zone |
|
833 | // Manages the hovered zone | |
835 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { |
|
834 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
836 | if (impl->m_HoveredZone) { |
|
835 | if (impl->m_HoveredZone) { | |
837 | impl->m_HoveredZone->setHovered(false); |
|
836 | impl->m_HoveredZone->setHovered(false); | |
838 | } |
|
837 | } | |
839 | selectionZoneItemUnderCursor->setHovered(true); |
|
838 | selectionZoneItemUnderCursor->setHovered(true); | |
840 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
839 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
841 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
840 | plot().replot(QCustomPlot::rpQueuedReplot); | |
842 | } |
|
841 | } | |
843 | } |
|
842 | } | |
844 | else { |
|
843 | else { | |
845 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
844 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
846 | if (impl->m_HoveredZone) { |
|
845 | if (impl->m_HoveredZone) { | |
847 | impl->m_HoveredZone->setHovered(false); |
|
846 | impl->m_HoveredZone->setHovered(false); | |
848 | impl->m_HoveredZone = nullptr; |
|
847 | impl->m_HoveredZone = nullptr; | |
849 | } |
|
848 | } | |
850 |
|
849 | |||
851 | setCursor(Qt::ArrowCursor); |
|
850 | setCursor(Qt::ArrowCursor); | |
852 | } |
|
851 | } | |
853 |
|
852 | |||
854 | impl->m_HasMovedMouse = true; |
|
853 | impl->m_HasMovedMouse = true; | |
855 | VisualizationDragWidget::mouseMoveEvent(event); |
|
854 | VisualizationDragWidget::mouseMoveEvent(event); | |
856 | } |
|
855 | } | |
857 |
|
856 | |||
858 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
857 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
859 | { |
|
858 | { | |
860 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
859 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
861 | if (value != 0) { |
|
860 | if (value != 0) { | |
862 |
|
861 | |||
863 | auto direction = value > 0 ? 1.0 : -1.0; |
|
862 | auto direction = value > 0 ? 1.0 : -1.0; | |
864 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
863 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
865 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
864 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
866 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
865 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
867 |
|
866 | |||
868 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
867 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
869 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
868 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
870 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
869 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
871 |
|
870 | |||
872 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
871 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
873 |
|
872 | |||
874 | if (!isZoomX && !isZoomY) { |
|
873 | if (!isZoomX && !isZoomY) { | |
875 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
874 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
876 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
875 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
877 |
|
876 | |||
878 | axis->setRange(axis->range() + diff); |
|
877 | axis->setRange(axis->range() + diff); | |
879 |
|
878 | |||
880 | if (plot().noAntialiasingOnDrag()) { |
|
879 | if (plot().noAntialiasingOnDrag()) { | |
881 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
880 | plot().setNotAntialiasedElements(QCP::aeAll); | |
882 | } |
|
881 | } | |
883 |
|
882 | |||
884 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
883 | plot().replot(QCustomPlot::rpQueuedReplot); | |
885 | } |
|
884 | } | |
886 | } |
|
885 | } | |
887 | } |
|
886 | } | |
888 |
|
887 | |||
889 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
888 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
890 | { |
|
889 | { | |
891 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
890 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
892 | auto isSelectionZoneMode |
|
891 | auto isSelectionZoneMode | |
893 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
892 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
894 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
893 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
895 |
|
894 | |||
896 | if (!isDragDropClick && isLeftClick) { |
|
895 | if (!isDragDropClick && isLeftClick) { | |
897 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
896 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { | |
898 | // Starts a zoom box |
|
897 | // Starts a zoom box | |
899 | impl->startDrawingRect(event->pos(), plot()); |
|
898 | impl->startDrawingRect(event->pos(), plot()); | |
900 | } |
|
899 | } | |
901 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { |
|
900 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { | |
902 | // Starts a new selection zone |
|
901 | // Starts a new selection zone | |
903 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); |
|
902 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); | |
904 | if (!zoneAtPos) { |
|
903 | if (!zoneAtPos) { | |
905 | impl->startDrawingZone(event->pos(), this); |
|
904 | impl->startDrawingZone(event->pos(), this); | |
906 | } |
|
905 | } | |
907 | } |
|
906 | } | |
908 | } |
|
907 | } | |
909 |
|
908 | |||
910 | // Allows mouse panning only in default mode |
|
909 | // Allows mouse panning only in default mode | |
911 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() |
|
910 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
912 | == SqpApplication::PlotsInteractionMode::None |
|
911 | == SqpApplication::PlotsInteractionMode::None | |
913 | && !isDragDropClick); |
|
912 | && !isDragDropClick); | |
914 |
|
913 | |||
915 | // Allows zone edition only in selection zone mode without drag&drop |
|
914 | // Allows zone edition only in selection zone mode without drag&drop | |
916 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
915 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
917 |
|
916 | |||
918 | // Selection / Deselection |
|
917 | // Selection / Deselection | |
919 | if (isSelectionZoneMode) { |
|
918 | if (isSelectionZoneMode) { | |
920 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
919 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
921 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
920 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
922 |
|
921 | |||
923 |
|
922 | |||
924 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
923 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
925 | && !isMultiSelectionClick) { |
|
924 | && !isMultiSelectionClick) { | |
926 | parentVisualizationWidget()->selectionZoneManager().select( |
|
925 | parentVisualizationWidget()->selectionZoneManager().select( | |
927 | {selectionZoneItemUnderCursor}); |
|
926 | {selectionZoneItemUnderCursor}); | |
928 | } |
|
927 | } | |
929 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { |
|
928 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { | |
930 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
929 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
931 | } |
|
930 | } | |
932 | else { |
|
931 | else { | |
933 | // No selection change |
|
932 | // No selection change | |
934 | } |
|
933 | } | |
935 |
|
934 | |||
936 | if (selectionZoneItemUnderCursor && isLeftClick) { |
|
935 | if (selectionZoneItemUnderCursor && isLeftClick) { | |
937 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
936 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
938 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
937 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
939 | } |
|
938 | } | |
940 | } |
|
939 | } | |
941 |
|
940 | |||
942 |
|
941 | |||
943 | impl->m_HasMovedMouse = false; |
|
942 | impl->m_HasMovedMouse = false; | |
944 | VisualizationDragWidget::mousePressEvent(event); |
|
943 | VisualizationDragWidget::mousePressEvent(event); | |
945 | } |
|
944 | } | |
946 |
|
945 | |||
947 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
946 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
948 | { |
|
947 | { | |
949 | if (impl->m_DrawingZoomRect) { |
|
948 | if (impl->m_DrawingZoomRect) { | |
950 |
|
949 | |||
951 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
950 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
952 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
951 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
953 |
|
952 | |||
954 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
953 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
955 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; |
|
954 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
956 |
|
955 | |||
957 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
956 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
958 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; |
|
957 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
959 |
|
958 | |||
960 | impl->removeDrawingRect(plot()); |
|
959 | impl->removeDrawingRect(plot()); | |
961 |
|
960 | |||
962 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
961 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
963 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { |
|
962 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { | |
964 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
963 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
965 | axisX->setRange(newAxisXRange); |
|
964 | axisX->setRange(newAxisXRange); | |
966 | axisY->setRange(newAxisYRange); |
|
965 | axisY->setRange(newAxisYRange); | |
967 |
|
966 | |||
968 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
967 | plot().replot(QCustomPlot::rpQueuedReplot); | |
969 | } |
|
968 | } | |
970 | } |
|
969 | } | |
971 |
|
970 | |||
972 | impl->endDrawingZone(this); |
|
971 | impl->endDrawingZone(this); | |
973 |
|
972 | |||
974 | // Selection / Deselection |
|
973 | // Selection / Deselection | |
975 | auto isSelectionZoneMode |
|
974 | auto isSelectionZoneMode | |
976 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
975 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
977 | if (isSelectionZoneMode) { |
|
976 | if (isSelectionZoneMode) { | |
978 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
977 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
979 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
978 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
980 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
979 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
981 | && !impl->m_HasMovedMouse) { |
|
980 | && !impl->m_HasMovedMouse) { | |
982 |
|
981 | |||
983 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
982 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
984 | if (zonesUnderCursor.count() > 1) { |
|
983 | if (zonesUnderCursor.count() > 1) { | |
985 | // There are multiple zones under the mouse. |
|
984 | // There are multiple zones under the mouse. | |
986 | // Performs the selection with a selection dialog. |
|
985 | // Performs the selection with a selection dialog. | |
987 | VisualizationMultiZoneSelectionDialog dialog{this}; |
|
986 | VisualizationMultiZoneSelectionDialog dialog{this}; | |
988 | dialog.setZones(zonesUnderCursor); |
|
987 | dialog.setZones(zonesUnderCursor); | |
989 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
988 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
990 | dialog.activateWindow(); |
|
989 | dialog.activateWindow(); | |
991 | dialog.raise(); |
|
990 | dialog.raise(); | |
992 | if (dialog.exec() == QDialog::Accepted) { |
|
991 | if (dialog.exec() == QDialog::Accepted) { | |
993 | auto selection = dialog.selectedZones(); |
|
992 | auto selection = dialog.selectedZones(); | |
994 |
|
993 | |||
995 | if (!isMultiSelectionClick) { |
|
994 | if (!isMultiSelectionClick) { | |
996 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
995 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
997 | } |
|
996 | } | |
998 |
|
997 | |||
999 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { |
|
998 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { | |
1000 | auto zone = it.key(); |
|
999 | auto zone = it.key(); | |
1001 | auto isSelected = it.value(); |
|
1000 | auto isSelected = it.value(); | |
1002 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, |
|
1001 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, | |
1003 | isSelected); |
|
1002 | isSelected); | |
1004 |
|
1003 | |||
1005 | if (isSelected) { |
|
1004 | if (isSelected) { | |
1006 | // Puts the zone on top of the stack so it can be moved or resized |
|
1005 | // Puts the zone on top of the stack so it can be moved or resized | |
1007 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
1006 | impl->moveSelectionZoneOnTop(zone, plot()); | |
1008 | } |
|
1007 | } | |
1009 | } |
|
1008 | } | |
1010 | } |
|
1009 | } | |
1011 | } |
|
1010 | } | |
1012 | else { |
|
1011 | else { | |
1013 | if (!isMultiSelectionClick) { |
|
1012 | if (!isMultiSelectionClick) { | |
1014 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1013 | parentVisualizationWidget()->selectionZoneManager().select( | |
1015 | {selectionZoneItemUnderCursor}); |
|
1014 | {selectionZoneItemUnderCursor}); | |
1016 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
1015 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
1017 | } |
|
1016 | } | |
1018 | else { |
|
1017 | else { | |
1019 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
1018 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
1020 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
1019 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |
1021 | || event->button() == Qt::RightButton); |
|
1020 | || event->button() == Qt::RightButton); | |
1022 | } |
|
1021 | } | |
1023 | } |
|
1022 | } | |
1024 | } |
|
1023 | } | |
1025 | else { |
|
1024 | else { | |
1026 | // No selection change |
|
1025 | // No selection change | |
1027 | } |
|
1026 | } | |
1028 | } |
|
1027 | } | |
1029 | } |
|
1028 | } | |
1030 |
|
1029 | |||
1031 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
1030 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
1032 | { |
|
1031 | { | |
1033 | auto graphRange = ui->widget->xAxis->range(); |
|
1032 | auto graphRange = ui->widget->xAxis->range(); | |
1034 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
1033 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
1035 |
|
1034 | |||
1036 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
1035 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
1037 | auto variable = variableEntry.first; |
|
1036 | auto variable = variableEntry.first; | |
1038 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1037 | qCDebug(LOG_VisualizationGraphWidget()) | |
1039 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
1038 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
1040 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1039 | qCDebug(LOG_VisualizationGraphWidget()) | |
1041 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
1040 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
1042 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
1041 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
1043 | impl->updateData(variableEntry.second, variable, variable->range()); |
|
1042 | impl->updateData(variableEntry.second, variable, variable->range()); | |
1044 | } |
|
1043 | } | |
1045 | } |
|
1044 | } | |
1046 | } |
|
1045 | } | |
1047 |
|
1046 | |||
1048 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
1047 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
1049 | const SqpRange &range) |
|
1048 | const SqpRange &range) | |
1050 | { |
|
1049 | { | |
1051 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
1050 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1052 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1051 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
1053 | impl->updateData(it->second, variable, range); |
|
1052 | impl->updateData(it->second, variable, range); | |
1054 | } |
|
1053 | } | |
1055 | } |
|
1054 | } |
General Comments 0
You need to be logged in to leave comments.
Login now