@@ -1,1578 +1,1578 | |||||
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 <Actions/FilteringAction.h> |
|
15 | #include <Actions/FilteringAction.h> | |
16 | #include <MimeTypes/MimeTypes.h> |
|
16 | #include <MimeTypes/MimeTypes.h> | |
17 | #include <cpp_utils_qt/cpp_utils_qt.hpp> |
|
17 | #include <cpp_utils_qt/cpp_utils_qt.hpp> | |
18 | #include <containers/algorithms.hpp> |
|
18 | #include <containers/algorithms.hpp> | |
19 | #include <Data/DateTimeRangeHelper.h> |
|
19 | #include <Data/DateTimeRangeHelper.h> | |
20 | #include <DragAndDrop/DragDropGuiController.h> |
|
20 | #include <DragAndDrop/DragDropGuiController.h> | |
21 | #include <Settings/SqpSettingsDefs.h> |
|
21 | #include <Settings/SqpSettingsDefs.h> | |
22 | #include <SqpApplication.h> |
|
22 | #include <SqpApplication.h> | |
23 | #include <Time/TimeController.h> |
|
23 | #include <Time/TimeController.h> | |
24 | #include <Variable/Variable2.h> |
|
24 | #include <Variable/Variable2.h> | |
25 | #include <Variable/VariableController2.h> |
|
25 | #include <Variable/VariableController2.h> | |
26 |
|
26 | |||
27 | #include <unordered_map> |
|
27 | #include <unordered_map> | |
28 |
|
28 | |||
29 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
29 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
30 |
|
30 | |||
31 | namespace |
|
31 | namespace | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | /// Key pressed to enable drag&drop in all modes |
|
34 | /// Key pressed to enable drag&drop in all modes | |
35 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; |
|
35 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; | |
36 |
|
36 | |||
37 | /// Key pressed to enable zoom on horizontal axis |
|
37 | /// Key pressed to enable zoom on horizontal axis | |
38 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
38 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
39 |
|
39 | |||
40 | /// Key pressed to enable zoom on vertical axis |
|
40 | /// Key pressed to enable zoom on vertical axis | |
41 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; |
|
41 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
42 |
|
42 | |||
43 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range |
|
43 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
44 | const auto PAN_SPEED = 5; |
|
44 | const auto PAN_SPEED = 5; | |
45 |
|
45 | |||
46 | /// Key pressed to enable a calibration pan |
|
46 | /// Key pressed to enable a calibration pan | |
47 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; |
|
47 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
48 |
|
48 | |||
49 | /// Key pressed to enable multi selection of selection zones |
|
49 | /// Key pressed to enable multi selection of selection zones | |
50 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; |
|
50 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; | |
51 |
|
51 | |||
52 | /// Minimum size for the zoom box, in percentage of the axis range |
|
52 | /// Minimum size for the zoom box, in percentage of the axis range | |
53 | const auto ZOOM_BOX_MIN_SIZE = 0.8; |
|
53 | const auto ZOOM_BOX_MIN_SIZE = 0.8; | |
54 |
|
54 | |||
55 | /// Format of the dates appearing in the label of a cursor |
|
55 | /// Format of the dates appearing in the label of a cursor | |
56 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); |
|
56 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); | |
57 |
|
57 | |||
58 | } // namespace |
|
58 | } // namespace | |
59 |
|
59 | |||
60 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate |
|
60 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate | |
61 | { |
|
61 | { | |
62 |
|
62 | |||
63 | explicit VisualizationGraphWidgetPrivate(const QString& name) |
|
63 | explicit VisualizationGraphWidgetPrivate(const QString& name) | |
64 | : m_Name { name } |
|
64 | : m_Name { name } | |
65 | , m_Flags { GraphFlag::EnableAll } |
|
65 | , m_Flags { GraphFlag::EnableAll } | |
66 | , m_IsCalibration { false } |
|
66 | , m_IsCalibration { false } | |
67 | , m_RenderingDelegate { nullptr } |
|
67 | , m_RenderingDelegate { nullptr } | |
68 | { |
|
68 | { | |
69 | m_plot = new QCustomPlot(); |
|
69 | m_plot = new QCustomPlot(); | |
70 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. |
|
70 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. | |
71 | m_plot->setPlottingHint(QCP::phFastPolylines, true); |
|
71 | m_plot->setPlottingHint(QCP::phFastPolylines, true); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void updateData( |
|
74 | void updateData( | |
75 | PlottablesMap& plottables, std::shared_ptr<Variable2> variable, const DateTimeRange& range) |
|
75 | PlottablesMap& plottables, std::shared_ptr<Variable2> variable, const DateTimeRange& range) | |
76 | { |
|
76 | { | |
77 | VisualizationGraphHelper::updateData(plottables, variable, range); |
|
77 | VisualizationGraphHelper::updateData(plottables, variable, range); | |
78 |
|
78 | |||
79 | // Prevents that data has changed to update rendering |
|
79 | // Prevents that data has changed to update rendering | |
80 | m_RenderingDelegate->onPlotUpdated(); |
|
80 | m_RenderingDelegate->onPlotUpdated(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QString m_Name; |
|
83 | QString m_Name; | |
84 | // 1 variable -> n qcpplot |
|
84 | // 1 variable -> n qcpplot | |
85 | std::map<std::shared_ptr<Variable2>, PlottablesMap> m_VariableToPlotMultiMap; |
|
85 | std::map<std::shared_ptr<Variable2>, PlottablesMap> m_VariableToPlotMultiMap; | |
86 | GraphFlags m_Flags; |
|
86 | GraphFlags m_Flags; | |
87 | bool m_IsCalibration; |
|
87 | bool m_IsCalibration; | |
88 | QCustomPlot* m_plot; |
|
88 | QCustomPlot* m_plot; | |
89 | QPoint m_lastMousePos; |
|
89 | QPoint m_lastMousePos; | |
90 | QCPRange m_lastXRange; |
|
90 | QCPRange m_lastXRange; | |
91 | QCPRange m_lastYRange; |
|
91 | QCPRange m_lastYRange; | |
92 | /// Delegate used to attach rendering features to the plot |
|
92 | /// Delegate used to attach rendering features to the plot | |
93 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
93 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
94 |
|
94 | |||
95 | QCPItemRect* m_DrawingZoomRect = nullptr; |
|
95 | QCPItemRect* m_DrawingZoomRect = nullptr; | |
96 | QStack<QPair<QCPRange, QCPRange>> m_ZoomStack; |
|
96 | QStack<QPair<QCPRange, QCPRange>> m_ZoomStack; | |
97 |
|
97 | |||
98 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
98 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; | |
99 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
99 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; | |
100 |
|
100 | |||
101 | VisualizationSelectionZoneItem* m_DrawingZone = nullptr; |
|
101 | VisualizationSelectionZoneItem* m_DrawingZone = nullptr; | |
102 | VisualizationSelectionZoneItem* m_HoveredZone = nullptr; |
|
102 | VisualizationSelectionZoneItem* m_HoveredZone = nullptr; | |
103 | QVector<VisualizationSelectionZoneItem*> m_SelectionZones; |
|
103 | QVector<VisualizationSelectionZoneItem*> m_SelectionZones; | |
104 |
|
104 | |||
105 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even |
|
105 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even | |
106 |
|
106 | |||
107 | bool m_VariableAutoRangeOnInit = true; |
|
107 | bool m_VariableAutoRangeOnInit = true; | |
108 |
|
108 | |||
109 | inline void enterPlotDrag(const QPoint& position) |
|
109 | inline void enterPlotDrag(const QPoint& position) | |
110 | { |
|
110 | { | |
111 | m_lastMousePos = m_plot->mapFromParent(position); |
|
111 | m_lastMousePos = m_plot->mapFromParent(position); | |
112 | m_lastXRange = m_plot->xAxis->range(); |
|
112 | m_lastXRange = m_plot->xAxis->range(); | |
113 | m_lastYRange = m_plot->yAxis->range(); |
|
113 | m_lastYRange = m_plot->yAxis->range(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | inline bool isDrawingZoomRect() { return m_DrawingZoomRect != nullptr; } |
|
116 | inline bool isDrawingZoomRect() { return m_DrawingZoomRect != nullptr; } | |
117 | void updateZoomRect(const QPoint& newPos) |
|
117 | void updateZoomRect(const QPoint& newPos) | |
118 | { |
|
118 | { | |
119 | QPointF pos { m_plot->xAxis->pixelToCoord(newPos.x()), |
|
119 | QPointF pos { m_plot->xAxis->pixelToCoord(newPos.x()), | |
120 | m_plot->yAxis->pixelToCoord(newPos.y()) }; |
|
120 | m_plot->yAxis->pixelToCoord(newPos.y()) }; | |
121 | m_DrawingZoomRect->bottomRight->setCoords(pos); |
|
121 | m_DrawingZoomRect->bottomRight->setCoords(pos); | |
122 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
122 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | void applyZoomRect() |
|
125 | void applyZoomRect() | |
126 | { |
|
126 | { | |
127 | auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom); |
|
127 | auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom); | |
128 | auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft); |
|
128 | auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft); | |
129 |
|
129 | |||
130 | auto newAxisXRange = QCPRange { m_DrawingZoomRect->topLeft->coords().x(), |
|
130 | auto newAxisXRange = QCPRange { m_DrawingZoomRect->topLeft->coords().x(), | |
131 | m_DrawingZoomRect->bottomRight->coords().x() }; |
|
131 | m_DrawingZoomRect->bottomRight->coords().x() }; | |
132 |
|
132 | |||
133 | auto newAxisYRange = QCPRange { m_DrawingZoomRect->topLeft->coords().y(), |
|
133 | auto newAxisYRange = QCPRange { m_DrawingZoomRect->topLeft->coords().y(), | |
134 | m_DrawingZoomRect->bottomRight->coords().y() }; |
|
134 | m_DrawingZoomRect->bottomRight->coords().y() }; | |
135 |
|
135 | |||
136 | removeDrawingRect(); |
|
136 | removeDrawingRect(); | |
137 |
|
137 | |||
138 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
138 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
139 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) |
|
139 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) | |
140 | { |
|
140 | { | |
141 | m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
141 | m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
142 | axisX->setRange(newAxisXRange); |
|
142 | axisX->setRange(newAxisXRange); | |
143 | axisY->setRange(newAxisYRange); |
|
143 | axisY->setRange(newAxisYRange); | |
144 |
|
144 | |||
145 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
145 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | inline bool isDrawingZoneRect() { return m_DrawingZone != nullptr; } |
|
149 | inline bool isDrawingZoneRect() { return m_DrawingZone != nullptr; } | |
150 | void updateZoneRect(const QPoint& newPos) |
|
150 | void updateZoneRect(const QPoint& newPos) | |
151 | { |
|
151 | { | |
152 | m_DrawingZone->setEnd(m_plot->xAxis->pixelToCoord(newPos.x())); |
|
152 | m_DrawingZone->setEnd(m_plot->xAxis->pixelToCoord(newPos.x())); | |
153 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
153 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void startDrawingRect(const QPoint& pos) |
|
156 | void startDrawingRect(const QPoint& pos) | |
157 | { |
|
157 | { | |
158 | removeDrawingRect(); |
|
158 | removeDrawingRect(); | |
159 |
|
159 | |||
160 | auto axisPos = posToAxisPos(pos); |
|
160 | auto axisPos = posToAxisPos(pos); | |
161 |
|
161 | |||
162 | m_DrawingZoomRect = new QCPItemRect { m_plot }; |
|
162 | m_DrawingZoomRect = new QCPItemRect { m_plot }; | |
163 | QPen p; |
|
163 | QPen p; | |
164 | p.setWidth(2); |
|
164 | p.setWidth(2); | |
165 | m_DrawingZoomRect->setPen(p); |
|
165 | m_DrawingZoomRect->setPen(p); | |
166 |
|
166 | |||
167 | m_DrawingZoomRect->topLeft->setCoords(axisPos); |
|
167 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
168 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
168 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void removeDrawingRect() |
|
171 | void removeDrawingRect() | |
172 | { |
|
172 | { | |
173 | if (m_DrawingZoomRect) |
|
173 | if (m_DrawingZoomRect) | |
174 | { |
|
174 | { | |
175 | m_plot->removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot |
|
175 | m_plot->removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
176 | m_DrawingZoomRect = nullptr; |
|
176 | m_DrawingZoomRect = nullptr; | |
177 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
177 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void selectZone(const QPoint& pos) |
|
181 | void selectZone(const QPoint& pos) | |
182 | { |
|
182 | { | |
183 | auto zoneAtPos = selectionZoneAt(pos); |
|
183 | auto zoneAtPos = selectionZoneAt(pos); | |
184 | setSelectionZonesEditionEnabled( |
|
184 | setSelectionZonesEditionEnabled( | |
185 | sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones); |
|
185 | sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void startDrawingZone(const QPoint& pos) |
|
188 | void startDrawingZone(const QPoint& pos) | |
189 | { |
|
189 | { | |
190 | endDrawingZone(); |
|
190 | endDrawingZone(); | |
191 |
|
191 | |||
192 | auto axisPos = posToAxisPos(pos); |
|
192 | auto axisPos = posToAxisPos(pos); | |
193 |
|
193 | |||
194 | m_DrawingZone = new VisualizationSelectionZoneItem { m_plot }; |
|
194 | m_DrawingZone = new VisualizationSelectionZoneItem { m_plot }; | |
195 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); |
|
195 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
196 | m_DrawingZone->setEditionEnabled(false); |
|
196 | m_DrawingZone->setEditionEnabled(false); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void endDrawingZone() |
|
199 | void endDrawingZone() | |
200 | { |
|
200 | { | |
201 | if (m_DrawingZone) |
|
201 | if (m_DrawingZone) | |
202 | { |
|
202 | { | |
203 | auto drawingZoneRange = m_DrawingZone->range(); |
|
203 | auto drawingZoneRange = m_DrawingZone->range(); | |
204 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) |
|
204 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) | |
205 | { |
|
205 | { | |
206 | m_DrawingZone->setEditionEnabled(true); |
|
206 | m_DrawingZone->setEditionEnabled(true); | |
207 | addSelectionZone(m_DrawingZone); |
|
207 | addSelectionZone(m_DrawingZone); | |
208 | } |
|
208 | } | |
209 | else |
|
209 | else | |
210 | { |
|
210 | { | |
211 | m_plot->removeItem(m_DrawingZone); |
|
211 | m_plot->removeItem(m_DrawingZone); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
214 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
215 | m_DrawingZone = nullptr; |
|
215 | m_DrawingZone = nullptr; | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void moveSelectionZone(const QPoint& destination) |
|
219 | void moveSelectionZone(const QPoint& destination) | |
220 | { |
|
220 | { | |
221 | /* |
|
221 | /* | |
222 | * I give up on this for now |
|
222 | * I give up on this for now | |
223 | * TODO implement this, the difficulty is that selection zones have their own |
|
223 | * TODO implement this, the difficulty is that selection zones have their own | |
224 | * event handling code which seems to rely on QCP GUI event handling propagation |
|
224 | * event handling code which seems to rely on QCP GUI event handling propagation | |
225 | * which was a realy bad design choice. |
|
225 | * which was a realy bad design choice. | |
226 | */ |
|
226 | */ | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | void setSelectionZonesEditionEnabled(bool value) |
|
229 | void setSelectionZonesEditionEnabled(bool value) | |
230 | { |
|
230 | { | |
231 | for (auto s : m_SelectionZones) |
|
231 | for (auto s : m_SelectionZones) | |
232 | { |
|
232 | { | |
233 | s->setEditionEnabled(value); |
|
233 | s->setEditionEnabled(value); | |
234 | } |
|
234 | } | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void addSelectionZone(VisualizationSelectionZoneItem* zone) { m_SelectionZones << zone; } |
|
237 | void addSelectionZone(VisualizationSelectionZoneItem* zone) { m_SelectionZones << zone; } | |
238 |
|
238 | |||
239 | VisualizationSelectionZoneItem* selectionZoneAt(const QPoint& pos) const |
|
239 | VisualizationSelectionZoneItem* selectionZoneAt(const QPoint& pos) const | |
240 | { |
|
240 | { | |
241 | VisualizationSelectionZoneItem* selectionZoneItemUnderCursor = nullptr; |
|
241 | VisualizationSelectionZoneItem* selectionZoneItemUnderCursor = nullptr; | |
242 | auto minDistanceToZone = -1; |
|
242 | auto minDistanceToZone = -1; | |
243 | for (auto zone : m_SelectionZones) |
|
243 | for (auto zone : m_SelectionZones) | |
244 | { |
|
244 | { | |
245 | auto distanceToZone = zone->selectTest(pos, false); |
|
245 | auto distanceToZone = zone->selectTest(pos, false); | |
246 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) |
|
246 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) | |
247 | && distanceToZone >= 0 && distanceToZone < m_plot->selectionTolerance()) |
|
247 | && distanceToZone >= 0 && distanceToZone < m_plot->selectionTolerance()) | |
248 | { |
|
248 | { | |
249 | selectionZoneItemUnderCursor = zone; |
|
249 | selectionZoneItemUnderCursor = zone; | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | return selectionZoneItemUnderCursor; |
|
253 | return selectionZoneItemUnderCursor; | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | QVector<VisualizationSelectionZoneItem*> selectionZonesAt( |
|
256 | QVector<VisualizationSelectionZoneItem*> selectionZonesAt( | |
257 | const QPoint& pos, const QCustomPlot& plot) const |
|
257 | const QPoint& pos, const QCustomPlot& plot) const | |
258 | { |
|
258 | { | |
259 | QVector<VisualizationSelectionZoneItem*> zones; |
|
259 | QVector<VisualizationSelectionZoneItem*> zones; | |
260 | for (auto zone : m_SelectionZones) |
|
260 | for (auto zone : m_SelectionZones) | |
261 | { |
|
261 | { | |
262 | auto distanceToZone = zone->selectTest(pos, false); |
|
262 | auto distanceToZone = zone->selectTest(pos, false); | |
263 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) |
|
263 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) | |
264 | { |
|
264 | { | |
265 | zones << zone; |
|
265 | zones << zone; | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | return zones; |
|
269 | return zones; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem* zone, QCustomPlot& plot) |
|
272 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem* zone, QCustomPlot& plot) | |
273 | { |
|
273 | { | |
274 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) |
|
274 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) | |
275 | { |
|
275 | { | |
276 | zone->moveToTop(); |
|
276 | zone->moveToTop(); | |
277 | m_SelectionZones.removeAll(zone); |
|
277 | m_SelectionZones.removeAll(zone); | |
278 | m_SelectionZones.append(zone); |
|
278 | m_SelectionZones.append(zone); | |
279 | } |
|
279 | } | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | QPointF posToAxisPos(const QPoint& pos) const |
|
282 | QPointF posToAxisPos(const QPoint& pos) const | |
283 | { |
|
283 | { | |
284 | auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom); |
|
284 | auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom); | |
285 | auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft); |
|
285 | auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft); | |
286 | return QPointF { axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y()) }; |
|
286 | return QPointF { axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y()) }; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | bool pointIsInAxisRect(const QPointF& axisPoint, QCustomPlot& plot) const |
|
289 | bool pointIsInAxisRect(const QPointF& axisPoint, QCustomPlot& plot) const | |
290 | { |
|
290 | { | |
291 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
291 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
292 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
292 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
293 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
293 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | inline QCPRange _pixDistanceToRange(double pos1, double pos2, QCPAxis* axis) |
|
296 | inline QCPRange _pixDistanceToRange(double pos1, double pos2, QCPAxis* axis) | |
297 | { |
|
297 | { | |
298 | if (axis->scaleType() == QCPAxis::stLinear) |
|
298 | if (axis->scaleType() == QCPAxis::stLinear) | |
299 | { |
|
299 | { | |
300 | auto diff = axis->pixelToCoord(pos1) - axis->pixelToCoord(pos2); |
|
300 | auto diff = axis->pixelToCoord(pos1) - axis->pixelToCoord(pos2); | |
301 | return QCPRange { axis->range().lower + diff, axis->range().upper + diff }; |
|
301 | return QCPRange { axis->range().lower + diff, axis->range().upper + diff }; | |
302 | } |
|
302 | } | |
303 | else |
|
303 | else | |
304 | { |
|
304 | { | |
305 | auto diff = axis->pixelToCoord(pos1) / axis->pixelToCoord(pos2); |
|
305 | auto diff = axis->pixelToCoord(pos1) / axis->pixelToCoord(pos2); | |
306 | return QCPRange { axis->range().lower * diff, axis->range().upper * diff }; |
|
306 | return QCPRange { axis->range().lower * diff, axis->range().upper * diff }; | |
307 | } |
|
307 | } | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | void setRange(const DateTimeRange& newRange, bool updateVar = true) |
|
310 | void setRange(const DateTimeRange& newRange, bool updateVar = true) | |
311 | { |
|
311 | { | |
312 | this->m_plot->xAxis->setRange(newRange.m_TStart, newRange.m_TEnd); |
|
312 | this->m_plot->xAxis->setRange(newRange.m_TStart, newRange.m_TEnd); | |
313 | if (updateVar) |
|
313 | if (updateVar) | |
314 | { |
|
314 | { | |
315 | for (auto it = m_VariableToPlotMultiMap.begin(), end = m_VariableToPlotMultiMap.end(); |
|
315 | for (auto it = m_VariableToPlotMultiMap.begin(), end = m_VariableToPlotMultiMap.end(); | |
316 | it != end; it = m_VariableToPlotMultiMap.upper_bound(it->first)) |
|
316 | it != end; it = m_VariableToPlotMultiMap.upper_bound(it->first)) | |
317 | { |
|
317 | { | |
318 | sqpApp->variableController().asyncChangeRange(it->first, newRange); |
|
318 | sqpApp->variableController().asyncChangeRange(it->first, newRange); | |
319 | } |
|
319 | } | |
320 | } |
|
320 | } | |
321 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
321 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void setRange(const QCPRange& newRange) |
|
324 | void setRange(const QCPRange& newRange) | |
325 | { |
|
325 | { | |
326 | auto graphRange = DateTimeRange { newRange.lower, newRange.upper }; |
|
326 | auto graphRange = DateTimeRange { newRange.lower, newRange.upper }; | |
327 | setRange(graphRange); |
|
327 | setRange(graphRange); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | void rescaleY() { m_plot->yAxis->rescale(true); } |
|
330 | void rescaleY() { m_plot->yAxis->rescale(true); } | |
331 |
|
331 | |||
332 | std::tuple<double, double> moveGraph(const QPoint& destination) |
|
332 | std::tuple<double, double> moveGraph(const QPoint& destination) | |
333 | { |
|
333 | { | |
334 | auto currentPos = m_plot->mapFromParent(destination); |
|
334 | auto currentPos = m_plot->mapFromParent(destination); | |
335 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); |
|
335 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
336 | auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical); |
|
336 | auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
337 | auto oldXRange = xAxis->range(); |
|
337 | auto oldXRange = xAxis->range(); | |
338 | auto oldYRange = yAxis->range(); |
|
338 | auto oldYRange = yAxis->range(); | |
339 | double dx = xAxis->pixelToCoord(m_lastMousePos.x()) - xAxis->pixelToCoord(currentPos.x()); |
|
339 | double dx = xAxis->pixelToCoord(m_lastMousePos.x()) - xAxis->pixelToCoord(currentPos.x()); | |
340 | xAxis->setRange(m_lastXRange.lower + dx, m_lastXRange.upper + dx); |
|
340 | xAxis->setRange(m_lastXRange.lower + dx, m_lastXRange.upper + dx); | |
341 | if (yAxis->scaleType() == QCPAxis::stLinear) |
|
341 | if (yAxis->scaleType() == QCPAxis::stLinear) | |
342 | { |
|
342 | { | |
343 | double dy |
|
343 | double dy | |
344 | = yAxis->pixelToCoord(m_lastMousePos.y()) - yAxis->pixelToCoord(currentPos.y()); |
|
344 | = yAxis->pixelToCoord(m_lastMousePos.y()) - yAxis->pixelToCoord(currentPos.y()); | |
345 | yAxis->setRange(m_lastYRange.lower + dy, m_lastYRange.upper + dy); |
|
345 | yAxis->setRange(m_lastYRange.lower + dy, m_lastYRange.upper + dy); | |
346 | } |
|
346 | } | |
347 | else |
|
347 | else | |
348 | { |
|
348 | { | |
349 | double dy |
|
349 | double dy | |
350 | = yAxis->pixelToCoord(m_lastMousePos.y()) / yAxis->pixelToCoord(currentPos.y()); |
|
350 | = yAxis->pixelToCoord(m_lastMousePos.y()) / yAxis->pixelToCoord(currentPos.y()); | |
351 | yAxis->setRange(m_lastYRange.lower * dy, m_lastYRange.upper * dy); |
|
351 | yAxis->setRange(m_lastYRange.lower * dy, m_lastYRange.upper * dy); | |
352 | } |
|
352 | } | |
353 | auto newXRange = xAxis->range(); |
|
353 | auto newXRange = xAxis->range(); | |
354 | auto newYRange = yAxis->range(); |
|
354 | auto newYRange = yAxis->range(); | |
355 | setRange(xAxis->range()); |
|
355 | setRange(xAxis->range()); | |
356 | // m_lastMousePos = currentPos; |
|
356 | // m_lastMousePos = currentPos; | |
357 | return { newXRange.lower - oldXRange.lower, newYRange.lower - oldYRange.lower }; |
|
357 | return { newXRange.lower - oldXRange.lower, newYRange.lower - oldYRange.lower }; | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | void zoom(double factor, int center, Qt::Orientation orientation) |
|
360 | void zoom(double factor, int center, Qt::Orientation orientation) | |
361 | { |
|
361 | { | |
362 | QCPAxis* axis = m_plot->axisRect()->rangeZoomAxis(orientation); |
|
362 | QCPAxis* axis = m_plot->axisRect()->rangeZoomAxis(orientation); | |
363 | axis->scaleRange(factor, axis->pixelToCoord(center)); |
|
363 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
364 | if (orientation == Qt::Horizontal) |
|
364 | if (orientation == Qt::Horizontal) | |
365 | setRange(axis->range()); |
|
365 | setRange(axis->range()); | |
366 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
366 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | void transform(const DateTimeRangeTransformation& tranformation) |
|
369 | void transform(const DateTimeRangeTransformation& tranformation) | |
370 | { |
|
370 | { | |
371 | auto graphRange = m_plot->xAxis->range(); |
|
371 | auto graphRange = m_plot->xAxis->range(); | |
372 | DateTimeRange range { graphRange.lower, graphRange.upper }; |
|
372 | DateTimeRange range { graphRange.lower, graphRange.upper }; | |
373 | range = range.transform(tranformation); |
|
373 | range = range.transform(tranformation); | |
374 | setRange(range); |
|
374 | setRange(range); | |
375 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
375 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void move(double dx, double dy) |
|
378 | void move(double dx, double dy) | |
379 | { |
|
379 | { | |
380 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); |
|
380 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
381 | auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical); |
|
381 | auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
382 | xAxis->setRange(QCPRange(xAxis->range().lower + dx, xAxis->range().upper + dx)); |
|
382 | xAxis->setRange(QCPRange(xAxis->range().lower + dx, xAxis->range().upper + dx)); | |
383 | yAxis->setRange(QCPRange(yAxis->range().lower + dy, yAxis->range().upper + dy)); |
|
383 | yAxis->setRange(QCPRange(yAxis->range().lower + dy, yAxis->range().upper + dy)); | |
384 | setRange(xAxis->range()); |
|
384 | setRange(xAxis->range()); | |
385 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
385 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void move(double factor, Qt::Orientation orientation) |
|
388 | void move(double factor, Qt::Orientation orientation) | |
389 | { |
|
389 | { | |
390 | auto oldRange = m_plot->xAxis->range(); |
|
390 | auto oldRange = m_plot->xAxis->range(); | |
391 | QCPAxis* axis = m_plot->axisRect()->rangeDragAxis(orientation); |
|
391 | QCPAxis* axis = m_plot->axisRect()->rangeDragAxis(orientation); | |
392 | if (m_plot->xAxis->scaleType() == QCPAxis::stLinear) |
|
392 | if (m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |
393 | { |
|
393 | { | |
394 | double rg = (axis->range().upper - axis->range().lower) * (factor / 10); |
|
394 | double rg = (axis->range().upper - axis->range().lower) * (factor / 10); | |
395 | axis->setRange(axis->range().lower + (rg), axis->range().upper + (rg)); |
|
395 | axis->setRange(axis->range().lower + (rg), axis->range().upper + (rg)); | |
396 | } |
|
396 | } | |
397 | else if (m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) |
|
397 | else if (m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | |
398 | { |
|
398 | { | |
399 | int start = 0, stop = 0; |
|
399 | int start = 0, stop = 0; | |
400 | double diff = 0.; |
|
400 | double diff = 0.; | |
401 | if (factor > 0.0) |
|
401 | if (factor > 0.0) | |
402 | { |
|
402 | { | |
403 | stop = m_plot->width() * factor / 10; |
|
403 | stop = m_plot->width() * factor / 10; | |
404 | start = 2 * m_plot->width() * factor / 10; |
|
404 | start = 2 * m_plot->width() * factor / 10; | |
405 | } |
|
405 | } | |
406 | if (factor < 0.0) |
|
406 | if (factor < 0.0) | |
407 | { |
|
407 | { | |
408 | factor *= -1.0; |
|
408 | factor *= -1.0; | |
409 | start = m_plot->width() * factor / 10; |
|
409 | start = m_plot->width() * factor / 10; | |
410 | stop = 2 * m_plot->width() * factor / 10; |
|
410 | stop = 2 * m_plot->width() * factor / 10; | |
411 | } |
|
411 | } | |
412 | diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); |
|
412 | diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); | |
413 | axis->setRange(m_plot->axisRect()->rangeDragAxis(orientation)->range().lower * diff, |
|
413 | axis->setRange(m_plot->axisRect()->rangeDragAxis(orientation)->range().lower * diff, | |
414 | m_plot->axisRect()->rangeDragAxis(orientation)->range().upper * diff); |
|
414 | m_plot->axisRect()->rangeDragAxis(orientation)->range().upper * diff); | |
415 | } |
|
415 | } | |
416 | if (orientation == Qt::Horizontal) |
|
416 | if (orientation == Qt::Horizontal) | |
417 | setRange(axis->range()); |
|
417 | setRange(axis->range()); | |
418 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
418 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
419 | } |
|
419 | } | |
420 | }; |
|
420 | }; | |
421 |
|
421 | |||
422 | VisualizationGraphWidget::VisualizationGraphWidget(const QString& name, QWidget* parent) |
|
422 | VisualizationGraphWidget::VisualizationGraphWidget(const QString& name, QWidget* parent) | |
423 | : VisualizationDragWidget { parent } |
|
423 | : VisualizationDragWidget { parent } | |
424 | , ui { new Ui::VisualizationGraphWidget } |
|
424 | , ui { new Ui::VisualizationGraphWidget } | |
425 | , impl { spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name) } |
|
425 | , impl { spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name) } | |
426 | { |
|
426 | { | |
427 | ui->setupUi(this); |
|
427 | ui->setupUi(this); | |
428 | this->layout()->addWidget(impl->m_plot); |
|
428 | this->layout()->addWidget(impl->m_plot); | |
429 | // 'Close' options : widget is deleted when closed |
|
429 | // 'Close' options : widget is deleted when closed | |
430 | setAttribute(Qt::WA_DeleteOnClose); |
|
430 | setAttribute(Qt::WA_DeleteOnClose); | |
431 |
|
431 | |||
432 | // The delegate must be initialized after the ui as it uses the plot |
|
432 | // The delegate must be initialized after the ui as it uses the plot | |
433 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
433 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
434 |
|
434 | |||
435 | // Init the cursors |
|
435 | // Init the cursors | |
436 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
436 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
437 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); |
|
437 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); | |
438 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
438 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
439 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); |
|
439 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); | |
440 |
|
440 | |||
441 | this->setFocusPolicy(Qt::WheelFocus); |
|
441 | this->setFocusPolicy(Qt::WheelFocus); | |
442 | this->setMouseTracking(true); |
|
442 | this->setMouseTracking(true); | |
443 | impl->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); |
|
443 | impl->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | |
444 | impl->m_plot->setContextMenuPolicy(Qt::CustomContextMenu); |
|
444 | impl->m_plot->setContextMenuPolicy(Qt::CustomContextMenu); | |
445 | impl->m_plot->setParent(this); |
|
445 | impl->m_plot->setParent(this); | |
446 |
|
446 | |||
447 | connect(&sqpApp->variableController(), &VariableController2::variableDeleted, this, |
|
447 | connect(&sqpApp->variableController(), &VariableController2::variableDeleted, this, | |
448 | &VisualizationGraphWidget::variableDeleted); |
|
448 | &VisualizationGraphWidget::variableDeleted); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 |
|
451 | |||
452 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
452 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
453 | { |
|
453 | { | |
454 | delete ui; |
|
454 | delete ui; | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | VisualizationZoneWidget* VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
457 | VisualizationZoneWidget* VisualizationGraphWidget::parentZoneWidget() const noexcept | |
458 | { |
|
458 | { | |
459 | auto parent = parentWidget(); |
|
459 | auto parent = parentWidget(); | |
460 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget*>(parent)) |
|
460 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget*>(parent)) | |
461 | { |
|
461 | { | |
462 | parent = parent->parentWidget(); |
|
462 | parent = parent->parentWidget(); | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | return qobject_cast<VisualizationZoneWidget*>(parent); |
|
465 | return qobject_cast<VisualizationZoneWidget*>(parent); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | VisualizationWidget* VisualizationGraphWidget::parentVisualizationWidget() const |
|
468 | VisualizationWidget* VisualizationGraphWidget::parentVisualizationWidget() const | |
469 | { |
|
469 | { | |
470 | auto parent = parentWidget(); |
|
470 | auto parent = parentWidget(); | |
471 | while (parent != nullptr && !qobject_cast<VisualizationWidget*>(parent)) |
|
471 | while (parent != nullptr && !qobject_cast<VisualizationWidget*>(parent)) | |
472 | { |
|
472 | { | |
473 | parent = parent->parentWidget(); |
|
473 | parent = parent->parentWidget(); | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | return qobject_cast<VisualizationWidget*>(parent); |
|
476 | return qobject_cast<VisualizationWidget*>(parent); | |
477 | } |
|
477 | } | |
478 |
|
478 | |||
479 | void VisualizationGraphWidget::setFlags(GraphFlags flags) |
|
479 | void VisualizationGraphWidget::setFlags(GraphFlags flags) | |
480 | { |
|
480 | { | |
481 | impl->m_Flags = std::move(flags); |
|
481 | impl->m_Flags = std::move(flags); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable2> variable, DateTimeRange range) |
|
484 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable2> variable, DateTimeRange range) | |
485 | { |
|
485 | { | |
486 | // Uses delegate to create the qcpplot components according to the variable |
|
486 | // Uses delegate to create the qcpplot components according to the variable | |
487 | auto createdPlottables = VisualizationGraphHelper::create(variable, *impl->m_plot); |
|
487 | auto createdPlottables = VisualizationGraphHelper::create(variable, *impl->m_plot); | |
488 |
|
488 | |||
489 | // Sets graph properties |
|
489 | // Sets graph properties | |
490 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); |
|
490 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); | |
491 |
|
491 | |||
492 | impl->m_VariableToPlotMultiMap.insert({ variable, std::move(createdPlottables) }); |
|
492 | impl->m_VariableToPlotMultiMap.insert({ variable, std::move(createdPlottables) }); | |
493 |
|
493 | |||
494 | setGraphRange(range); |
|
494 | setGraphRange(range); | |
495 | // If the variable already has its data loaded, load its units and its range in the graph |
|
495 | // If the variable already has its data loaded, load its units and its range in the graph | |
496 | if (variable->data() != nullptr) |
|
496 | if (variable->data() != nullptr) | |
497 | { |
|
497 | { | |
498 | impl->m_RenderingDelegate->setAxesUnits(*variable); |
|
498 | impl->m_RenderingDelegate->setAxesUnits(*variable); | |
499 | } |
|
499 | } | |
500 | else |
|
500 | else | |
501 | { |
|
501 | { | |
502 | auto context = new QObject { this }; |
|
502 | auto context = new QObject { this }; | |
503 | connect( |
|
503 | connect( | |
504 | variable.get(), &Variable2::updated, context, [this, variable, context, range](QUuid) { |
|
504 | variable.get(), &Variable2::updated, context, [this, variable, context, range](QUuid) { | |
505 | this->impl->m_RenderingDelegate->setAxesUnits(*variable); |
|
505 | this->impl->m_RenderingDelegate->setAxesUnits(*variable); | |
506 | this->impl->m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
506 | this->impl->m_plot->replot(QCustomPlot::rpQueuedReplot); | |
507 | delete context; |
|
507 | delete context; | |
508 | }); |
|
508 | }); | |
509 | } |
|
509 | } | |
510 | //TODO this is bad! when variable is moved to another graph it still fires |
|
510 | //TODO this is bad! when variable is moved to another graph it still fires | |
511 | // even if this has been deleted |
|
511 | // even if this has been deleted | |
512 | connect(variable.get(), &Variable2::updated, this, &VisualizationGraphWidget::variableUpdated); |
|
512 | connect(variable.get(), &Variable2::updated, this, &VisualizationGraphWidget::variableUpdated); | |
513 | this->onUpdateVarDisplaying(variable, range); // My bullshit |
|
513 | this->onUpdateVarDisplaying(variable, range); // My bullshit | |
514 | emit variableAdded(variable); |
|
514 | emit variableAdded(variable); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable2> variable) noexcept |
|
517 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable2> variable) noexcept | |
518 | { |
|
518 | { | |
519 | // Each component associated to the variable : |
|
519 | // Each component associated to the variable : | |
520 | // - is removed from qcpplot (which deletes it) |
|
520 | // - is removed from qcpplot (which deletes it) | |
521 | // - is no longer referenced in the map |
|
521 | // - is no longer referenced in the map | |
522 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
522 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
523 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) |
|
523 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) | |
524 | { |
|
524 | { | |
525 | emit variableAboutToBeRemoved(variable); |
|
525 | emit variableAboutToBeRemoved(variable); | |
526 |
|
526 | |||
527 | auto& plottablesMap = variableIt->second; |
|
527 | auto& plottablesMap = variableIt->second; | |
528 |
|
528 | |||
529 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
529 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
530 | plottableIt != plottableEnd;) |
|
530 | plottableIt != plottableEnd;) | |
531 | { |
|
531 | { | |
532 | impl->m_plot->removePlottable(plottableIt->second); |
|
532 | impl->m_plot->removePlottable(plottableIt->second); | |
533 | plottableIt = plottablesMap.erase(plottableIt); |
|
533 | plottableIt = plottablesMap.erase(plottableIt); | |
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
536 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | // Updates graph |
|
539 | // Updates graph | |
540 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
540 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); | |
541 | } |
|
541 | } | |
542 |
|
542 | |||
543 | std::vector<std::shared_ptr<Variable2>> VisualizationGraphWidget::variables() const |
|
543 | std::vector<std::shared_ptr<Variable2>> VisualizationGraphWidget::variables() const | |
544 | { |
|
544 | { | |
545 | auto variables = std::vector<std::shared_ptr<Variable2>> {}; |
|
545 | auto variables = std::vector<std::shared_ptr<Variable2>> {}; | |
546 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
546 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
547 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) |
|
547 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) | |
548 | { |
|
548 | { | |
549 | variables.push_back(it->first); |
|
549 | variables.push_back(it->first); | |
550 | } |
|
550 | } | |
551 |
|
551 | |||
552 | return variables; |
|
552 | return variables; | |
553 | } |
|
553 | } | |
554 |
|
554 | |||
555 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable2> variable) |
|
555 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable2> variable) | |
556 | { |
|
556 | { | |
557 | if (!variable) |
|
557 | if (!variable) | |
558 | { |
|
558 | { | |
559 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
559 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
560 | return; |
|
560 | return; | |
561 | } |
|
561 | } | |
562 |
|
562 | |||
563 | VisualizationGraphHelper::setYAxisRange(variable, *impl->m_plot); |
|
563 | VisualizationGraphHelper::setYAxisRange(variable, *impl->m_plot); | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | DateTimeRange VisualizationGraphWidget::graphRange() const noexcept |
|
566 | DateTimeRange VisualizationGraphWidget::graphRange() const noexcept | |
567 | { |
|
567 | { | |
568 | auto graphRange = impl->m_plot->xAxis->range(); |
|
568 | auto graphRange = impl->m_plot->xAxis->range(); | |
569 | return DateTimeRange { graphRange.lower, graphRange.upper }; |
|
569 | return DateTimeRange { graphRange.lower, graphRange.upper }; | |
570 | } |
|
570 | } | |
571 |
|
571 | |||
572 | void VisualizationGraphWidget::setGraphRange( |
|
572 | void VisualizationGraphWidget::setGraphRange( | |
573 | const DateTimeRange& range, bool updateVar, bool forward) |
|
573 | const DateTimeRange& range, bool updateVar, bool forward) | |
574 | { |
|
574 | { | |
575 | impl->setRange(range, updateVar); |
|
575 | impl->setRange(range, updateVar); | |
576 | if (forward) |
|
576 | if (forward) | |
577 | { |
|
577 | { | |
578 | emit this->setrange_sig(this->graphRange(), true, false); |
|
578 | emit this->setrange_sig(this->graphRange(), true, false); | |
579 | } |
|
579 | } | |
580 | } |
|
580 | } | |
581 |
|
581 | |||
582 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) |
|
582 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) | |
583 | { |
|
583 | { | |
584 | impl->m_VariableAutoRangeOnInit = value; |
|
584 | impl->m_VariableAutoRangeOnInit = value; | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | QVector<DateTimeRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
587 | QVector<DateTimeRange> VisualizationGraphWidget::selectionZoneRanges() const | |
588 | { |
|
588 | { | |
589 | QVector<DateTimeRange> ranges; |
|
589 | QVector<DateTimeRange> ranges; | |
590 | for (auto zone : impl->m_SelectionZones) |
|
590 | for (auto zone : impl->m_SelectionZones) | |
591 | { |
|
591 | { | |
592 | ranges << zone->range(); |
|
592 | ranges << zone->range(); | |
593 | } |
|
593 | } | |
594 |
|
594 | |||
595 | return ranges; |
|
595 | return ranges; | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | void VisualizationGraphWidget::addSelectionZones(const QVector<DateTimeRange>& ranges) |
|
598 | void VisualizationGraphWidget::addSelectionZones(const QVector<DateTimeRange>& ranges) | |
599 | { |
|
599 | { | |
600 | for (const auto& range : ranges) |
|
600 | for (const auto& range : ranges) | |
601 | { |
|
601 | { | |
602 | // note: ownership is transfered to QCustomPlot |
|
602 | // note: ownership is transfered to QCustomPlot | |
603 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
603 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
604 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
604 | zone->setRange(range.m_TStart, range.m_TEnd); | |
605 | impl->addSelectionZone(zone); |
|
605 | impl->addSelectionZone(zone); | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
608 | plot().replot(QCustomPlot::rpQueuedReplot); | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | VisualizationSelectionZoneItem* VisualizationGraphWidget::addSelectionZone( |
|
611 | VisualizationSelectionZoneItem* VisualizationGraphWidget::addSelectionZone( | |
612 | const QString& name, const DateTimeRange& range) |
|
612 | const QString& name, const DateTimeRange& range) | |
613 | { |
|
613 | { | |
614 | // note: ownership is transfered to QCustomPlot |
|
614 | // note: ownership is transfered to QCustomPlot | |
615 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
615 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
616 | zone->setName(name); |
|
616 | zone->setName(name); | |
617 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
617 | zone->setRange(range.m_TStart, range.m_TEnd); | |
618 | impl->addSelectionZone(zone); |
|
618 | impl->addSelectionZone(zone); | |
619 |
|
619 | |||
620 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
620 | plot().replot(QCustomPlot::rpQueuedReplot); | |
621 |
|
621 | |||
622 | return zone; |
|
622 | return zone; | |
623 | } |
|
623 | } | |
624 |
|
624 | |||
625 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem* selectionZone) |
|
625 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem* selectionZone) | |
626 | { |
|
626 | { | |
627 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
627 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
628 |
|
628 | |||
629 | if (impl->m_HoveredZone == selectionZone) |
|
629 | if (impl->m_HoveredZone == selectionZone) | |
630 | { |
|
630 | { | |
631 | impl->m_HoveredZone = nullptr; |
|
631 | impl->m_HoveredZone = nullptr; | |
632 | setCursor(Qt::ArrowCursor); |
|
632 | setCursor(Qt::ArrowCursor); | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 | impl->m_SelectionZones.removeAll(selectionZone); |
|
635 | impl->m_SelectionZones.removeAll(selectionZone); | |
636 | plot().removeItem(selectionZone); |
|
636 | plot().removeItem(selectionZone); | |
637 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
637 | plot().replot(QCustomPlot::rpQueuedReplot); | |
638 | } |
|
638 | } | |
639 |
|
639 | |||
640 | void VisualizationGraphWidget::undoZoom() |
|
640 | void VisualizationGraphWidget::undoZoom() | |
641 | { |
|
641 | { | |
642 | auto zoom = impl->m_ZoomStack.pop(); |
|
642 | auto zoom = impl->m_ZoomStack.pop(); | |
643 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
643 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
644 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
644 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
645 |
|
645 | |||
646 | axisX->setRange(zoom.first); |
|
646 | axisX->setRange(zoom.first); | |
647 | axisY->setRange(zoom.second); |
|
647 | axisY->setRange(zoom.second); | |
648 |
|
648 | |||
649 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
649 | plot().replot(QCustomPlot::rpQueuedReplot); | |
650 | } |
|
650 | } | |
651 |
|
651 | |||
652 | void VisualizationGraphWidget::zoom( |
|
652 | void VisualizationGraphWidget::zoom( | |
653 | double factor, int center, Qt::Orientation orientation, bool forward) |
|
653 | double factor, int center, Qt::Orientation orientation, bool forward) | |
654 | { |
|
654 | { | |
655 | impl->zoom(factor, center, orientation); |
|
655 | impl->zoom(factor, center, orientation); | |
656 | if (forward && orientation == Qt::Horizontal) |
|
656 | if (forward && orientation == Qt::Horizontal) | |
657 | emit this->setrange_sig(this->graphRange(), true, false); |
|
657 | emit this->setrange_sig(this->graphRange(), true, false); | |
658 | } |
|
658 | } | |
659 |
|
659 | |||
660 | void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation, bool forward) |
|
660 | void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation, bool forward) | |
661 | { |
|
661 | { | |
662 | impl->move(factor, orientation); |
|
662 | impl->move(factor, orientation); | |
663 | if (forward) |
|
663 | if (forward) | |
664 | emit this->setrange_sig(this->graphRange(), true, false); |
|
664 | emit this->setrange_sig(this->graphRange(), true, false); | |
665 | } |
|
665 | } | |
666 |
|
666 | |||
667 | void VisualizationGraphWidget::move(double dx, double dy, bool forward) |
|
667 | void VisualizationGraphWidget::move(double dx, double dy, bool forward) | |
668 | { |
|
668 | { | |
669 | impl->move(dx, dy); |
|
669 | impl->move(dx, dy); | |
670 | if (forward) |
|
670 | if (forward) | |
671 | emit this->setrange_sig(this->graphRange(), true, false); |
|
671 | emit this->setrange_sig(this->graphRange(), true, false); | |
672 | } |
|
672 | } | |
673 |
|
673 | |||
674 | void VisualizationGraphWidget::transform( |
|
674 | void VisualizationGraphWidget::transform( | |
675 | const DateTimeRangeTransformation& tranformation, bool forward) |
|
675 | const DateTimeRangeTransformation& tranformation, bool forward) | |
676 | { |
|
676 | { | |
677 | impl->transform(tranformation); |
|
677 | impl->transform(tranformation); | |
678 | if (forward) |
|
678 | if (forward) | |
679 | emit this->setrange_sig(this->graphRange(), true, false); |
|
679 | emit this->setrange_sig(this->graphRange(), true, false); | |
680 | } |
|
680 | } | |
681 |
|
681 | |||
682 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor* visitor) |
|
682 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor* visitor) | |
683 | { |
|
683 | { | |
684 | if (visitor) |
|
684 | if (visitor) | |
685 | { |
|
685 | { | |
686 | visitor->visit(this); |
|
686 | visitor->visit(this); | |
687 | } |
|
687 | } | |
688 | else |
|
688 | else | |
689 | { |
|
689 | { | |
690 | qCCritical(LOG_VisualizationGraphWidget()) |
|
690 | qCCritical(LOG_VisualizationGraphWidget()) | |
691 | << tr("Can't visit widget : the visitor is null"); |
|
691 | << tr("Can't visit widget : the visitor is null"); | |
692 | } |
|
692 | } | |
693 | } |
|
693 | } | |
694 |
|
694 | |||
695 | bool VisualizationGraphWidget::canDrop(Variable2& variable) const |
|
695 | bool VisualizationGraphWidget::canDrop(Variable2& variable) const | |
696 | { |
|
696 | { | |
697 | auto isSpectrogram |
|
697 | auto isSpectrogram | |
698 | = [](auto& variable) { return variable.type() == DataSeriesType::SPECTROGRAM; }; |
|
698 | = [](auto& variable) { return variable.type() == DataSeriesType::SPECTROGRAM; }; | |
699 |
|
699 | |||
700 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
700 | // - A spectrogram series can't be dropped on graph with existing plottables | |
701 | // - No data series can be dropped on graph with existing spectrogram series |
|
701 | // - No data series can be dropped on graph with existing spectrogram series | |
702 | return isSpectrogram(variable) |
|
702 | return isSpectrogram(variable) | |
703 | ? impl->m_VariableToPlotMultiMap.empty() |
|
703 | ? impl->m_VariableToPlotMultiMap.empty() | |
704 | : std::none_of(impl->m_VariableToPlotMultiMap.cbegin(), |
|
704 | : std::none_of(impl->m_VariableToPlotMultiMap.cbegin(), | |
705 | impl->m_VariableToPlotMultiMap.cend(), |
|
705 | impl->m_VariableToPlotMultiMap.cend(), | |
706 | [isSpectrogram](const auto& entry) { return isSpectrogram(*entry.first); }); |
|
706 | [isSpectrogram](const auto& entry) { return isSpectrogram(*entry.first); }); | |
707 | } |
|
707 | } | |
708 |
|
708 | |||
709 | bool VisualizationGraphWidget::contains(Variable2& variable) const |
|
709 | bool VisualizationGraphWidget::contains(Variable2& variable) const | |
710 | { |
|
710 | { | |
711 | // Finds the variable among the keys of the map |
|
711 | // Finds the variable among the keys of the map | |
712 | auto variablePtr = &variable; |
|
712 | auto variablePtr = &variable; | |
713 | auto findVariable |
|
713 | auto findVariable | |
714 | = [variablePtr](const auto& entry) { return variablePtr == entry.first.get(); }; |
|
714 | = [variablePtr](const auto& entry) { return variablePtr == entry.first.get(); }; | |
715 |
|
715 | |||
716 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
716 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
717 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
717 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
718 | return it != end; |
|
718 | return it != end; | |
719 | } |
|
719 | } | |
720 |
|
720 | |||
721 | QString VisualizationGraphWidget::name() const |
|
721 | QString VisualizationGraphWidget::name() const | |
722 | { |
|
722 | { | |
723 | return impl->m_Name; |
|
723 | return impl->m_Name; | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | QMimeData* VisualizationGraphWidget::mimeData(const QPoint& position) const |
|
726 | QMimeData* VisualizationGraphWidget::mimeData(const QPoint& position) const | |
727 | { |
|
727 | { | |
728 | auto mimeData = new QMimeData; |
|
728 | auto mimeData = new QMimeData; | |
729 |
|
729 | |||
730 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position); |
|
730 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position); | |
731 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
731 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
732 | && selectionZoneItemUnderCursor) |
|
732 | && selectionZoneItemUnderCursor) | |
733 | { |
|
733 | { | |
734 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, |
|
734 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, | |
735 | TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); |
|
735 | TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); | |
736 | mimeData->setData(MIME::MIME_TYPE_SELECTION_ZONE, |
|
736 | mimeData->setData(MIME::MIME_TYPE_SELECTION_ZONE, | |
737 | TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); |
|
737 | TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); | |
738 | } |
|
738 | } | |
739 | else |
|
739 | else | |
740 | { |
|
740 | { | |
741 | mimeData->setData(MIME::MIME_TYPE_GRAPH, QByteArray {}); |
|
741 | mimeData->setData(MIME::MIME_TYPE_GRAPH, QByteArray {}); | |
742 |
|
742 | |||
743 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
743 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
744 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData); |
|
744 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData); | |
745 | } |
|
745 | } | |
746 |
|
746 | |||
747 | return mimeData; |
|
747 | return mimeData; | |
748 | } |
|
748 | } | |
749 |
|
749 | |||
750 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint& dragPosition) |
|
750 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint& dragPosition) | |
751 | { |
|
751 | { | |
752 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition); |
|
752 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition); | |
753 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
753 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
754 | && selectionZoneItemUnderCursor) |
|
754 | && selectionZoneItemUnderCursor) | |
755 | { |
|
755 | { | |
756 |
|
756 | |||
757 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
757 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
758 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
758 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
759 |
|
759 | |||
760 | auto zoneSize = QSizeF { qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
760 | auto zoneSize = QSizeF { qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
761 | qAbs(zoneBottomRight.y() - zoneTopLeft.y()) } |
|
761 | qAbs(zoneBottomRight.y() - zoneTopLeft.y()) } | |
762 | .toSize(); |
|
762 | .toSize(); | |
763 |
|
763 | |||
764 | auto pixmap = QPixmap(zoneSize); |
|
764 | auto pixmap = QPixmap(zoneSize); | |
765 | render(&pixmap, QPoint(), QRegion { QRect { zoneTopLeft.toPoint(), zoneSize } }); |
|
765 | render(&pixmap, QPoint(), QRegion { QRect { zoneTopLeft.toPoint(), zoneSize } }); | |
766 |
|
766 | |||
767 | return pixmap; |
|
767 | return pixmap; | |
768 | } |
|
768 | } | |
769 |
|
769 | |||
770 | return QPixmap(); |
|
770 | return QPixmap(); | |
771 | } |
|
771 | } | |
772 |
|
772 | |||
773 | bool VisualizationGraphWidget::isDragAllowed() const |
|
773 | bool VisualizationGraphWidget::isDragAllowed() const | |
774 | { |
|
774 | { | |
775 | return true; |
|
775 | return true; | |
776 | } |
|
776 | } | |
777 |
|
777 | |||
778 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
778 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
779 | { |
|
779 | { | |
780 | if (highlighted) |
|
780 | if (highlighted) | |
781 | { |
|
781 | { | |
782 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
782 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
783 | } |
|
783 | } | |
784 | else |
|
784 | else | |
785 | { |
|
785 | { | |
786 | plot().setBackground(QBrush(Qt::white)); |
|
786 | plot().setBackground(QBrush(Qt::white)); | |
787 | } |
|
787 | } | |
788 |
|
788 | |||
789 | plot().update(); |
|
789 | plot().update(); | |
790 | } |
|
790 | } | |
791 |
|
791 | |||
792 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
792 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
793 | { |
|
793 | { | |
794 | impl->m_VerticalCursor->setPosition(time); |
|
794 | impl->m_VerticalCursor->setPosition(time); | |
795 | impl->m_VerticalCursor->setVisible(true); |
|
795 | impl->m_VerticalCursor->setVisible(true); | |
796 |
|
796 | |||
797 | auto text |
|
797 | auto text | |
798 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
798 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
799 | impl->m_VerticalCursor->setLabelText(text); |
|
799 | impl->m_VerticalCursor->setLabelText(text); | |
800 | } |
|
800 | } | |
801 |
|
801 | |||
802 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
802 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
803 | { |
|
803 | { | |
804 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
804 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
805 | impl->m_VerticalCursor->setVisible(true); |
|
805 | impl->m_VerticalCursor->setVisible(true); | |
806 |
|
806 | |||
807 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
807 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
808 | auto text |
|
808 | auto text | |
809 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
809 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
810 | impl->m_VerticalCursor->setLabelText(text); |
|
810 | impl->m_VerticalCursor->setLabelText(text); | |
811 | } |
|
811 | } | |
812 |
|
812 | |||
813 | void VisualizationGraphWidget::removeVerticalCursor() |
|
813 | void VisualizationGraphWidget::removeVerticalCursor() | |
814 | { |
|
814 | { | |
815 | impl->m_VerticalCursor->setVisible(false); |
|
815 | impl->m_VerticalCursor->setVisible(false); | |
816 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
816 | plot().replot(QCustomPlot::rpQueuedReplot); | |
817 | } |
|
817 | } | |
818 |
|
818 | |||
819 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
819 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
820 | { |
|
820 | { | |
821 | impl->m_HorizontalCursor->setPosition(value); |
|
821 | impl->m_HorizontalCursor->setPosition(value); | |
822 | impl->m_HorizontalCursor->setVisible(true); |
|
822 | impl->m_HorizontalCursor->setVisible(true); | |
823 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
823 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
824 | } |
|
824 | } | |
825 |
|
825 | |||
826 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
826 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
827 | { |
|
827 | { | |
828 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
828 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
829 | impl->m_HorizontalCursor->setVisible(true); |
|
829 | impl->m_HorizontalCursor->setVisible(true); | |
830 |
|
830 | |||
831 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
831 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
832 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
832 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
833 | } |
|
833 | } | |
834 |
|
834 | |||
835 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
835 | void VisualizationGraphWidget::removeHorizontalCursor() | |
836 | { |
|
836 | { | |
837 | impl->m_HorizontalCursor->setVisible(false); |
|
837 | impl->m_HorizontalCursor->setVisible(false); | |
838 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
838 | plot().replot(QCustomPlot::rpQueuedReplot); | |
839 | } |
|
839 | } | |
840 |
|
840 | |||
841 | void VisualizationGraphWidget::closeEvent(QCloseEvent* event) |
|
841 | void VisualizationGraphWidget::closeEvent(QCloseEvent* event) | |
842 | { |
|
842 | { | |
843 | Q_UNUSED(event); |
|
843 | Q_UNUSED(event); | |
844 |
|
844 | |||
845 | for (auto i : impl->m_SelectionZones) |
|
845 | for (auto i : impl->m_SelectionZones) | |
846 | { |
|
846 | { | |
847 | parentVisualizationWidget()->selectionZoneManager().setSelected(i, false); |
|
847 | parentVisualizationWidget()->selectionZoneManager().setSelected(i, false); | |
848 | } |
|
848 | } | |
849 |
|
849 | |||
850 | // Prevents that all variables will be removed from graph when it will be closed |
|
850 | // Prevents that all variables will be removed from graph when it will be closed | |
851 | for (auto& variableEntry : impl->m_VariableToPlotMultiMap) |
|
851 | for (auto& variableEntry : impl->m_VariableToPlotMultiMap) | |
852 | { |
|
852 | { | |
853 | emit variableAboutToBeRemoved(variableEntry.first); |
|
853 | emit variableAboutToBeRemoved(variableEntry.first); | |
854 | } |
|
854 | } | |
855 | } |
|
855 | } | |
856 |
|
856 | |||
857 | void VisualizationGraphWidget::enterEvent(QEvent* event) |
|
857 | void VisualizationGraphWidget::enterEvent(QEvent* event) | |
858 | { |
|
858 | { | |
859 | Q_UNUSED(event); |
|
859 | Q_UNUSED(event); | |
860 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
860 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
861 | } |
|
861 | } | |
862 |
|
862 | |||
863 | void VisualizationGraphWidget::leaveEvent(QEvent* event) |
|
863 | void VisualizationGraphWidget::leaveEvent(QEvent* event) | |
864 | { |
|
864 | { | |
865 | Q_UNUSED(event); |
|
865 | Q_UNUSED(event); | |
866 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
866 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
867 |
|
867 | |||
868 | if (auto parentZone = parentZoneWidget()) |
|
868 | if (auto parentZone = parentZoneWidget()) | |
869 | { |
|
869 | { | |
870 | parentZone->notifyMouseLeaveGraph(this); |
|
870 | parentZone->notifyMouseLeaveGraph(this); | |
871 | } |
|
871 | } | |
872 | else |
|
872 | else | |
873 | { |
|
873 | { | |
874 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
874 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
875 | } |
|
875 | } | |
876 |
|
876 | |||
877 | if (impl->m_HoveredZone) |
|
877 | if (impl->m_HoveredZone) | |
878 | { |
|
878 | { | |
879 | impl->m_HoveredZone->setHovered(false); |
|
879 | impl->m_HoveredZone->setHovered(false); | |
880 | impl->m_HoveredZone = nullptr; |
|
880 | impl->m_HoveredZone = nullptr; | |
881 | } |
|
881 | } | |
882 | } |
|
882 | } | |
883 |
|
883 | |||
884 | void VisualizationGraphWidget::wheelEvent(QWheelEvent* event) |
|
884 | void VisualizationGraphWidget::wheelEvent(QWheelEvent* event) | |
885 | { |
|
885 | { | |
886 | double factor; |
|
886 | double factor; | |
887 | double wheelSteps = event->delta() / 120.0; // a single step delta is +/-120 usually |
|
887 | double wheelSteps = event->delta() / 120.0; // a single step delta is +/-120 usually | |
888 | if (event->modifiers() == Qt::ControlModifier) |
|
888 | if (event->modifiers() == Qt::ControlModifier) | |
889 | { |
|
889 | { | |
890 | if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical)) |
|
890 | if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical)) | |
891 | { |
|
891 | { | |
892 | setCursor(Qt::SizeVerCursor); |
|
892 | setCursor(Qt::SizeVerCursor); | |
893 | factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); |
|
893 | factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |
894 | zoom(factor, event->pos().y(), Qt::Vertical); |
|
894 | zoom(factor, event->pos().y(), Qt::Vertical); | |
895 | } |
|
895 | } | |
896 | } |
|
896 | } | |
897 | else if (event->modifiers() == Qt::ShiftModifier) |
|
897 | else if (event->modifiers() == Qt::ShiftModifier) | |
898 | { |
|
898 | { | |
899 | if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical)) |
|
899 | if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical)) | |
900 | { |
|
900 | { | |
901 | setCursor(Qt::SizeHorCursor); |
|
901 | setCursor(Qt::SizeHorCursor); | |
902 | factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); |
|
902 | factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |
903 | zoom(factor, event->pos().x(), Qt::Horizontal); |
|
903 | zoom(factor, event->pos().x(), Qt::Horizontal); | |
904 | } |
|
904 | } | |
905 | } |
|
905 | } | |
906 | else |
|
906 | else | |
907 | { |
|
907 | { | |
908 | move(wheelSteps, Qt::Horizontal); |
|
908 | move(wheelSteps, Qt::Horizontal); | |
909 | } |
|
909 | } | |
910 | event->accept(); |
|
910 | event->accept(); | |
911 | } |
|
911 | } | |
912 |
|
912 | |||
913 |
|
913 | |||
914 | void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent* event) |
|
914 | void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent* event) | |
915 | { |
|
915 | { | |
916 | if (impl->isDrawingZoomRect()) |
|
916 | if (impl->isDrawingZoomRect()) | |
917 | { |
|
917 | { | |
918 | impl->updateZoomRect(event->pos()); |
|
918 | impl->updateZoomRect(event->pos()); | |
919 | } |
|
919 | } | |
920 | else if (impl->isDrawingZoneRect()) |
|
920 | else if (impl->isDrawingZoneRect()) | |
921 | { |
|
921 | { | |
922 | impl->updateZoneRect(event->pos()); |
|
922 | impl->updateZoneRect(event->pos()); | |
923 | } |
|
923 | } | |
924 | else if (event->buttons() == Qt::LeftButton) |
|
924 | else if (event->buttons() == Qt::LeftButton) | |
925 | { |
|
925 | { | |
926 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::None) |
|
926 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::None) | |
927 | { |
|
927 | { | |
928 | auto [dx, dy] = impl->moveGraph(event->pos()); |
|
928 | auto [dx, dy] = impl->moveGraph(event->pos()); | |
929 | emit this->setrange_sig(this->graphRange(), true, false); |
|
929 | emit this->setrange_sig(this->graphRange(), true, false); | |
930 | } |
|
930 | } | |
931 | else if (sqpApp->plotsInteractionMode() |
|
931 | else if (sqpApp->plotsInteractionMode() | |
932 | == SqpApplication::PlotsInteractionMode::SelectionZones) |
|
932 | == SqpApplication::PlotsInteractionMode::SelectionZones) | |
933 | { |
|
933 | { | |
934 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); |
|
934 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); | |
935 | if (auto item = impl->m_plot->itemAt(posInPlot)) |
|
935 | if (auto item = impl->m_plot->itemAt(posInPlot)) | |
936 | { |
|
936 | { | |
937 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) |
|
937 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) | |
938 | { |
|
938 | { | |
939 | QMouseEvent e { QEvent::MouseMove, posInPlot, event->button(), event->buttons(), |
|
939 | QMouseEvent e { QEvent::MouseMove, posInPlot, event->button(), event->buttons(), | |
940 | event->modifiers() }; |
|
940 | event->modifiers() }; | |
941 | sqpApp->sendEvent(this->impl->m_plot, &e); |
|
941 | sqpApp->sendEvent(this->impl->m_plot, &e); | |
942 | this->impl->m_plot->replot(QCustomPlot::rpImmediateRefresh); |
|
942 | this->impl->m_plot->replot(QCustomPlot::rpImmediateRefresh); | |
943 | } |
|
943 | } | |
944 | } |
|
944 | } | |
945 | } |
|
945 | } | |
946 | } |
|
946 | } | |
947 | else |
|
947 | else | |
948 | { |
|
948 | { | |
949 | impl->m_RenderingDelegate->updateTooltip(event); |
|
949 | impl->m_RenderingDelegate->updateTooltip(event); | |
950 | } |
|
950 | } | |
951 | // event->accept(); |
|
951 | // event->accept(); | |
952 |
|
|
952 | VisualizationDragWidget::mouseMoveEvent(event); | |
953 | } |
|
953 | } | |
954 |
|
954 | |||
955 | void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent* event) |
|
955 | void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent* event) | |
956 | { |
|
956 | { | |
957 | if (impl->isDrawingZoomRect()) |
|
957 | if (impl->isDrawingZoomRect()) | |
958 | { |
|
958 | { | |
959 | auto oldRange = this->graphRange(); |
|
959 | auto oldRange = this->graphRange(); | |
960 | impl->applyZoomRect(); |
|
960 | impl->applyZoomRect(); | |
961 | auto newRange = this->graphRange(); |
|
961 | auto newRange = this->graphRange(); | |
962 | if (auto tf = DateTimeRangeHelper::computeTransformation(oldRange, newRange)) |
|
962 | if (auto tf = DateTimeRangeHelper::computeTransformation(oldRange, newRange)) | |
963 | emit this->transform_sig(tf.value(), false); |
|
963 | emit this->transform_sig(tf.value(), false); | |
964 | } |
|
964 | } | |
965 | else if (impl->isDrawingZoneRect()) |
|
965 | else if (impl->isDrawingZoneRect()) | |
966 | { |
|
966 | { | |
967 | impl->endDrawingZone(); |
|
967 | impl->endDrawingZone(); | |
968 | } |
|
968 | } | |
969 | else |
|
969 | else | |
970 | { |
|
970 | { | |
971 | setCursor(Qt::ArrowCursor); |
|
971 | setCursor(Qt::ArrowCursor); | |
972 | } |
|
972 | } | |
973 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); |
|
973 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); | |
974 | if (auto item = impl->m_plot->itemAt(posInPlot)) |
|
974 | if (auto item = impl->m_plot->itemAt(posInPlot)) | |
975 | { |
|
975 | { | |
976 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) |
|
976 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) | |
977 | { |
|
977 | { | |
978 | QMouseEvent e { QEvent::MouseButtonRelease, posInPlot, event->button(), |
|
978 | QMouseEvent e { QEvent::MouseButtonRelease, posInPlot, event->button(), | |
979 | event->buttons(), event->modifiers() }; |
|
979 | event->buttons(), event->modifiers() }; | |
980 | sqpApp->sendEvent(this->impl->m_plot, &e); |
|
980 | sqpApp->sendEvent(this->impl->m_plot, &e); | |
981 | } |
|
981 | } | |
982 | } |
|
982 | } | |
983 | event->accept(); |
|
983 | event->accept(); | |
984 | } |
|
984 | } | |
985 |
|
985 | |||
986 | void VisualizationGraphWidget::mousePressEvent(QMouseEvent* event) |
|
986 | void VisualizationGraphWidget::mousePressEvent(QMouseEvent* event) | |
987 | { |
|
987 | { | |
988 | if (event->button() == Qt::RightButton) |
|
988 | if (event->button() == Qt::RightButton) | |
989 | { |
|
989 | { | |
990 | onGraphMenuRequested(event->pos()); |
|
990 | onGraphMenuRequested(event->pos()); | |
991 | } |
|
991 | } | |
992 | else |
|
992 | else | |
993 | { |
|
993 | { | |
994 | auto selectedZone = impl->selectionZoneAt(event->pos()); |
|
994 | auto selectedZone = impl->selectionZoneAt(event->pos()); | |
995 | switch (sqpApp->plotsInteractionMode()) |
|
995 | switch (sqpApp->plotsInteractionMode()) | |
996 | { |
|
996 | { | |
997 | case SqpApplication::PlotsInteractionMode::DragAndDrop: |
|
997 | case SqpApplication::PlotsInteractionMode::DragAndDrop: | |
998 | break; |
|
998 | break; | |
999 | case SqpApplication::PlotsInteractionMode::SelectionZones: |
|
999 | case SqpApplication::PlotsInteractionMode::SelectionZones: | |
1000 | impl->setSelectionZonesEditionEnabled(true); |
|
1000 | impl->setSelectionZonesEditionEnabled(true); | |
1001 | if ((event->modifiers() == Qt::ControlModifier) && (selectedZone != nullptr)) |
|
1001 | if ((event->modifiers() == Qt::ControlModifier) && (selectedZone != nullptr)) | |
1002 | { |
|
1002 | { | |
1003 | auto alreadySelectedZones |
|
1003 | auto alreadySelectedZones | |
1004 | = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
1004 | = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
1005 | selectedZone->setAssociatedEditedZones(alreadySelectedZones); |
|
1005 | selectedZone->setAssociatedEditedZones(alreadySelectedZones); | |
1006 | if (cpp_utils::containers::contains(alreadySelectedZones, selectedZone)) |
|
1006 | if (cpp_utils::containers::contains(alreadySelectedZones, selectedZone)) | |
1007 | { |
|
1007 | { | |
1008 | alreadySelectedZones.removeOne(selectedZone); |
|
1008 | alreadySelectedZones.removeOne(selectedZone); | |
1009 | } |
|
1009 | } | |
1010 | else |
|
1010 | else | |
1011 | { |
|
1011 | { | |
1012 | alreadySelectedZones.append(selectedZone); |
|
1012 | alreadySelectedZones.append(selectedZone); | |
1013 | } |
|
1013 | } | |
1014 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1014 | parentVisualizationWidget()->selectionZoneManager().select( | |
1015 | alreadySelectedZones); |
|
1015 | alreadySelectedZones); | |
1016 | } |
|
1016 | } | |
1017 | else |
|
1017 | else | |
1018 | { |
|
1018 | { | |
1019 | if (!selectedZone) |
|
1019 | if (!selectedZone) | |
1020 | { |
|
1020 | { | |
1021 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
1021 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
1022 | impl->startDrawingZone(event->pos()); |
|
1022 | impl->startDrawingZone(event->pos()); | |
1023 | } |
|
1023 | } | |
1024 | else |
|
1024 | else | |
1025 | { |
|
1025 | { | |
1026 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1026 | parentVisualizationWidget()->selectionZoneManager().select( | |
1027 | { selectedZone }); |
|
1027 | { selectedZone }); | |
1028 | } |
|
1028 | } | |
1029 | } |
|
1029 | } | |
1030 | { |
|
1030 | { | |
1031 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); |
|
1031 | auto posInPlot = this->impl->m_plot->mapFromParent(event->pos()); | |
1032 | if (auto item = impl->m_plot->itemAt(posInPlot)) |
|
1032 | if (auto item = impl->m_plot->itemAt(posInPlot)) | |
1033 | { |
|
1033 | { | |
1034 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) |
|
1034 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) | |
1035 | { |
|
1035 | { | |
1036 | QMouseEvent e { QEvent::MouseButtonPress, posInPlot, event->button(), |
|
1036 | QMouseEvent e { QEvent::MouseButtonPress, posInPlot, event->button(), | |
1037 | event->buttons(), event->modifiers() }; |
|
1037 | event->buttons(), event->modifiers() }; | |
1038 | sqpApp->sendEvent(this->impl->m_plot, &e); |
|
1038 | sqpApp->sendEvent(this->impl->m_plot, &e); | |
1039 | } |
|
1039 | } | |
1040 | } |
|
1040 | } | |
1041 | } |
|
1041 | } | |
1042 | break; |
|
1042 | break; | |
1043 | case SqpApplication::PlotsInteractionMode::ZoomBox: |
|
1043 | case SqpApplication::PlotsInteractionMode::ZoomBox: | |
1044 | impl->startDrawingRect(event->pos()); |
|
1044 | impl->startDrawingRect(event->pos()); | |
1045 | break; |
|
1045 | break; | |
1046 | default: |
|
1046 | default: | |
1047 | if (auto item = impl->m_plot->itemAt(event->pos())) |
|
1047 | if (auto item = impl->m_plot->itemAt(event->pos())) | |
1048 | { |
|
1048 | { | |
1049 | emit impl->m_plot->itemClick(item, event); |
|
1049 | emit impl->m_plot->itemClick(item, event); | |
1050 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) |
|
1050 | if (qobject_cast<VisualizationSelectionZoneItem*>(item)) | |
1051 | { |
|
1051 | { | |
1052 | setCursor(Qt::ClosedHandCursor); |
|
1052 | setCursor(Qt::ClosedHandCursor); | |
1053 | impl->enterPlotDrag(event->pos()); |
|
1053 | impl->enterPlotDrag(event->pos()); | |
1054 | } |
|
1054 | } | |
1055 | } |
|
1055 | } | |
1056 | else |
|
1056 | else | |
1057 | { |
|
1057 | { | |
1058 | setCursor(Qt::ClosedHandCursor); |
|
1058 | setCursor(Qt::ClosedHandCursor); | |
1059 | impl->enterPlotDrag(event->pos()); |
|
1059 | impl->enterPlotDrag(event->pos()); | |
1060 | } |
|
1060 | } | |
1061 | } |
|
1061 | } | |
1062 | } |
|
1062 | } | |
1063 | // event->accept(); |
|
1063 | // event->accept(); | |
1064 |
|
|
1064 | VisualizationDragWidget::mousePressEvent(event); | |
1065 | } |
|
1065 | } | |
1066 |
|
1066 | |||
1067 | void VisualizationGraphWidget::mouseDoubleClickEvent(QMouseEvent* event) |
|
1067 | void VisualizationGraphWidget::mouseDoubleClickEvent(QMouseEvent* event) | |
1068 | { |
|
1068 | { | |
1069 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
1069 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
1070 | } |
|
1070 | } | |
1071 |
|
1071 | |||
1072 | void VisualizationGraphWidget::keyReleaseEvent(QKeyEvent* event) |
|
1072 | void VisualizationGraphWidget::keyReleaseEvent(QKeyEvent* event) | |
1073 | { |
|
1073 | { | |
1074 | switch (event->key()) |
|
1074 | switch (event->key()) | |
1075 | { |
|
1075 | { | |
1076 | case Qt::Key_Control: |
|
1076 | case Qt::Key_Control: | |
1077 | event->accept(); |
|
1077 | event->accept(); | |
1078 | break; |
|
1078 | break; | |
1079 | case Qt::Key_Shift: |
|
1079 | case Qt::Key_Shift: | |
1080 | event->accept(); |
|
1080 | event->accept(); | |
1081 | break; |
|
1081 | break; | |
1082 | default: |
|
1082 | default: | |
1083 | QWidget::keyReleaseEvent(event); |
|
1083 | QWidget::keyReleaseEvent(event); | |
1084 | break; |
|
1084 | break; | |
1085 | } |
|
1085 | } | |
1086 | setCursor(Qt::ArrowCursor); |
|
1086 | setCursor(Qt::ArrowCursor); | |
1087 | // event->accept(); |
|
1087 | // event->accept(); | |
1088 | } |
|
1088 | } | |
1089 |
|
1089 | |||
1090 | void VisualizationGraphWidget::keyPressEvent(QKeyEvent* event) |
|
1090 | void VisualizationGraphWidget::keyPressEvent(QKeyEvent* event) | |
1091 | { |
|
1091 | { | |
1092 | switch (event->key()) |
|
1092 | switch (event->key()) | |
1093 | { |
|
1093 | { | |
1094 | case Qt::Key_Control: |
|
1094 | case Qt::Key_Control: | |
1095 | setCursor(Qt::CrossCursor); |
|
1095 | setCursor(Qt::CrossCursor); | |
1096 | break; |
|
1096 | break; | |
1097 | case Qt::Key_Shift: |
|
1097 | case Qt::Key_Shift: | |
1098 | break; |
|
1098 | break; | |
1099 | case Qt::Key_M: |
|
1099 | case Qt::Key_M: | |
1100 | impl->rescaleY(); |
|
1100 | impl->rescaleY(); | |
1101 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
1101 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); | |
1102 | break; |
|
1102 | break; | |
1103 | case Qt::Key_Left: |
|
1103 | case Qt::Key_Left: | |
1104 | if (event->modifiers() != Qt::ControlModifier) |
|
1104 | if (event->modifiers() != Qt::ControlModifier) | |
1105 | { |
|
1105 | { | |
1106 | move(-0.1, Qt::Horizontal); |
|
1106 | move(-0.1, Qt::Horizontal); | |
1107 | } |
|
1107 | } | |
1108 | else |
|
1108 | else | |
1109 | { |
|
1109 | { | |
1110 | zoom(2, this->width() / 2, Qt::Horizontal); |
|
1110 | zoom(2, this->width() / 2, Qt::Horizontal); | |
1111 | } |
|
1111 | } | |
1112 | break; |
|
1112 | break; | |
1113 | case Qt::Key_Right: |
|
1113 | case Qt::Key_Right: | |
1114 | if (event->modifiers() != Qt::ControlModifier) |
|
1114 | if (event->modifiers() != Qt::ControlModifier) | |
1115 | { |
|
1115 | { | |
1116 | move(0.1, Qt::Horizontal); |
|
1116 | move(0.1, Qt::Horizontal); | |
1117 | } |
|
1117 | } | |
1118 | else |
|
1118 | else | |
1119 | { |
|
1119 | { | |
1120 | zoom(0.5, this->width() / 2, Qt::Horizontal); |
|
1120 | zoom(0.5, this->width() / 2, Qt::Horizontal); | |
1121 | } |
|
1121 | } | |
1122 | break; |
|
1122 | break; | |
1123 | case Qt::Key_Up: |
|
1123 | case Qt::Key_Up: | |
1124 | if (event->modifiers() != Qt::ControlModifier) |
|
1124 | if (event->modifiers() != Qt::ControlModifier) | |
1125 | { |
|
1125 | { | |
1126 | move(0.1, Qt::Vertical); |
|
1126 | move(0.1, Qt::Vertical); | |
1127 | } |
|
1127 | } | |
1128 | else |
|
1128 | else | |
1129 | { |
|
1129 | { | |
1130 | zoom(0.5, this->height() / 2, Qt::Vertical); |
|
1130 | zoom(0.5, this->height() / 2, Qt::Vertical); | |
1131 | } |
|
1131 | } | |
1132 | break; |
|
1132 | break; | |
1133 | case Qt::Key_Down: |
|
1133 | case Qt::Key_Down: | |
1134 | if (event->modifiers() != Qt::ControlModifier) |
|
1134 | if (event->modifiers() != Qt::ControlModifier) | |
1135 | { |
|
1135 | { | |
1136 | move(-0.1, Qt::Vertical); |
|
1136 | move(-0.1, Qt::Vertical); | |
1137 | } |
|
1137 | } | |
1138 | else |
|
1138 | else | |
1139 | { |
|
1139 | { | |
1140 | zoom(2, this->height() / 2, Qt::Vertical); |
|
1140 | zoom(2, this->height() / 2, Qt::Vertical); | |
1141 | } |
|
1141 | } | |
1142 | break; |
|
1142 | break; | |
1143 | default: |
|
1143 | default: | |
1144 | QWidget::keyPressEvent(event); |
|
1144 | QWidget::keyPressEvent(event); | |
1145 | break; |
|
1145 | break; | |
1146 | } |
|
1146 | } | |
1147 | } |
|
1147 | } | |
1148 |
|
1148 | |||
1149 | QCustomPlot& VisualizationGraphWidget::plot() const noexcept |
|
1149 | QCustomPlot& VisualizationGraphWidget::plot() const noexcept | |
1150 | { |
|
1150 | { | |
1151 | return *impl->m_plot; |
|
1151 | return *impl->m_plot; | |
1152 | } |
|
1152 | } | |
1153 |
|
1153 | |||
1154 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint& pos) noexcept |
|
1154 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint& pos) noexcept | |
1155 | { |
|
1155 | { | |
1156 | QMenu graphMenu {}; |
|
1156 | QMenu graphMenu {}; | |
1157 |
|
1157 | |||
1158 | // Iterates on variables (unique keys) |
|
1158 | // Iterates on variables (unique keys) | |
1159 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
1159 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
1160 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
1160 | end = impl->m_VariableToPlotMultiMap.cend(); | |
1161 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) |
|
1161 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) | |
1162 | { |
|
1162 | { | |
1163 | // 'Remove variable' action |
|
1163 | // 'Remove variable' action | |
1164 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
1164 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
1165 | [this, var = it->first]() { removeVariable(var); }); |
|
1165 | [this, var = it->first]() { removeVariable(var); }); | |
1166 | } |
|
1166 | } | |
1167 |
|
1167 | |||
1168 | if (!impl->m_ZoomStack.isEmpty()) |
|
1168 | if (!impl->m_ZoomStack.isEmpty()) | |
1169 | { |
|
1169 | { | |
1170 | if (!graphMenu.isEmpty()) |
|
1170 | if (!graphMenu.isEmpty()) | |
1171 | { |
|
1171 | { | |
1172 | graphMenu.addSeparator(); |
|
1172 | graphMenu.addSeparator(); | |
1173 | } |
|
1173 | } | |
1174 |
|
1174 | |||
1175 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
1175 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
1176 | } |
|
1176 | } | |
1177 |
|
1177 | |||
1178 | // Selection Zone Actions |
|
1178 | // Selection Zone Actions | |
1179 | auto selectionZoneItem = impl->selectionZoneAt(pos); |
|
1179 | auto selectionZoneItem = impl->selectionZoneAt(pos); | |
1180 | if (selectionZoneItem) |
|
1180 | if (selectionZoneItem) | |
1181 | { |
|
1181 | { | |
1182 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
1182 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
1183 | selectedItems.removeAll(selectionZoneItem); |
|
1183 | selectedItems.removeAll(selectionZoneItem); | |
1184 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
1184 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
1185 |
|
1185 | |||
1186 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
1186 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
1187 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) |
|
1187 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) | |
1188 | { |
|
1188 | { | |
1189 | graphMenu.addSeparator(); |
|
1189 | graphMenu.addSeparator(); | |
1190 | } |
|
1190 | } | |
1191 |
|
1191 | |||
1192 | QHash<QString, QMenu*> subMenus; |
|
1192 | QHash<QString, QMenu*> subMenus; | |
1193 | QHash<QString, bool> subMenusEnabled; |
|
1193 | QHash<QString, bool> subMenusEnabled; | |
1194 | QHash<QString, FilteringAction*> filteredMenu; |
|
1194 | QHash<QString, FilteringAction*> filteredMenu; | |
1195 |
|
1195 | |||
1196 | for (auto zoneAction : zoneActions) |
|
1196 | for (auto zoneAction : zoneActions) | |
1197 | { |
|
1197 | { | |
1198 |
|
1198 | |||
1199 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
1199 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
1200 |
|
1200 | |||
1201 | auto menu = &graphMenu; |
|
1201 | auto menu = &graphMenu; | |
1202 | QString menuPath; |
|
1202 | QString menuPath; | |
1203 | for (auto subMenuName : zoneAction->subMenuList()) |
|
1203 | for (auto subMenuName : zoneAction->subMenuList()) | |
1204 | { |
|
1204 | { | |
1205 | menuPath += '/'; |
|
1205 | menuPath += '/'; | |
1206 | menuPath += subMenuName; |
|
1206 | menuPath += subMenuName; | |
1207 |
|
1207 | |||
1208 | if (!subMenus.contains(menuPath)) |
|
1208 | if (!subMenus.contains(menuPath)) | |
1209 | { |
|
1209 | { | |
1210 | menu = menu->addMenu(subMenuName); |
|
1210 | menu = menu->addMenu(subMenuName); | |
1211 | subMenus[menuPath] = menu; |
|
1211 | subMenus[menuPath] = menu; | |
1212 | subMenusEnabled[menuPath] = isEnabled; |
|
1212 | subMenusEnabled[menuPath] = isEnabled; | |
1213 | } |
|
1213 | } | |
1214 | else |
|
1214 | else | |
1215 | { |
|
1215 | { | |
1216 | menu = subMenus.value(menuPath); |
|
1216 | menu = subMenus.value(menuPath); | |
1217 | if (isEnabled) |
|
1217 | if (isEnabled) | |
1218 | { |
|
1218 | { | |
1219 | // The sub menu is enabled if at least one of its actions is enabled |
|
1219 | // The sub menu is enabled if at least one of its actions is enabled | |
1220 | subMenusEnabled[menuPath] = true; |
|
1220 | subMenusEnabled[menuPath] = true; | |
1221 | } |
|
1221 | } | |
1222 | } |
|
1222 | } | |
1223 | } |
|
1223 | } | |
1224 |
|
1224 | |||
1225 | FilteringAction* filterAction = nullptr; |
|
1225 | FilteringAction* filterAction = nullptr; | |
1226 | if (sqpApp->actionsGuiController().isMenuFiltered(zoneAction->subMenuList())) |
|
1226 | if (sqpApp->actionsGuiController().isMenuFiltered(zoneAction->subMenuList())) | |
1227 | { |
|
1227 | { | |
1228 | filterAction = filteredMenu.value(menuPath); |
|
1228 | filterAction = filteredMenu.value(menuPath); | |
1229 | if (!filterAction) |
|
1229 | if (!filterAction) | |
1230 | { |
|
1230 | { | |
1231 | filterAction = new FilteringAction { this }; |
|
1231 | filterAction = new FilteringAction { this }; | |
1232 | filteredMenu[menuPath] = filterAction; |
|
1232 | filteredMenu[menuPath] = filterAction; | |
1233 | menu->addAction(filterAction); |
|
1233 | menu->addAction(filterAction); | |
1234 | } |
|
1234 | } | |
1235 | } |
|
1235 | } | |
1236 |
|
1236 | |||
1237 | auto action = menu->addAction(zoneAction->name()); |
|
1237 | auto action = menu->addAction(zoneAction->name()); | |
1238 | action->setEnabled(isEnabled); |
|
1238 | action->setEnabled(isEnabled); | |
1239 | action->setShortcut(zoneAction->displayedShortcut()); |
|
1239 | action->setShortcut(zoneAction->displayedShortcut()); | |
1240 | QObject::connect(action, &QAction::triggered, |
|
1240 | QObject::connect(action, &QAction::triggered, | |
1241 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
1241 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
1242 |
|
1242 | |||
1243 | if (filterAction && zoneAction->isFilteringAllowed()) |
|
1243 | if (filterAction && zoneAction->isFilteringAllowed()) | |
1244 | { |
|
1244 | { | |
1245 | filterAction->addActionToFilter(action); |
|
1245 | filterAction->addActionToFilter(action); | |
1246 | } |
|
1246 | } | |
1247 | } |
|
1247 | } | |
1248 |
|
1248 | |||
1249 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) |
|
1249 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) | |
1250 | { |
|
1250 | { | |
1251 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
1251 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
1252 | } |
|
1252 | } | |
1253 | } |
|
1253 | } | |
1254 |
|
1254 | |||
1255 | if (!graphMenu.isEmpty()) |
|
1255 | if (!graphMenu.isEmpty()) | |
1256 | { |
|
1256 | { | |
1257 | graphMenu.exec(QCursor::pos()); |
|
1257 | graphMenu.exec(QCursor::pos()); | |
1258 | } |
|
1258 | } | |
1259 | } |
|
1259 | } | |
1260 |
|
1260 | |||
1261 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent* event) noexcept |
|
1261 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent* event) noexcept | |
1262 | { |
|
1262 | { | |
1263 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
1263 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
1264 | } |
|
1264 | } | |
1265 |
|
1265 | |||
1266 | void VisualizationGraphWidget::onMouseMove(QMouseEvent* event) noexcept |
|
1266 | void VisualizationGraphWidget::onMouseMove(QMouseEvent* event) noexcept | |
1267 | { |
|
1267 | { | |
1268 | // Handles plot rendering when mouse is moving |
|
1268 | // Handles plot rendering when mouse is moving | |
1269 | impl->m_RenderingDelegate->updateTooltip(event); |
|
1269 | impl->m_RenderingDelegate->updateTooltip(event); | |
1270 |
|
1270 | |||
1271 | auto axisPos = impl->posToAxisPos(event->pos()); |
|
1271 | auto axisPos = impl->posToAxisPos(event->pos()); | |
1272 |
|
1272 | |||
1273 | // Zoom box and zone drawing |
|
1273 | // Zoom box and zone drawing | |
1274 | if (impl->m_DrawingZoomRect) |
|
1274 | if (impl->m_DrawingZoomRect) | |
1275 | { |
|
1275 | { | |
1276 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
1276 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
1277 | } |
|
1277 | } | |
1278 | else if (impl->m_DrawingZone) |
|
1278 | else if (impl->m_DrawingZone) | |
1279 | { |
|
1279 | { | |
1280 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
1280 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
1281 | } |
|
1281 | } | |
1282 |
|
1282 | |||
1283 | // Cursor |
|
1283 | // Cursor | |
1284 | if (auto parentZone = parentZoneWidget()) |
|
1284 | if (auto parentZone = parentZoneWidget()) | |
1285 | { |
|
1285 | { | |
1286 | if (impl->pointIsInAxisRect(axisPos, plot())) |
|
1286 | if (impl->pointIsInAxisRect(axisPos, plot())) | |
1287 | { |
|
1287 | { | |
1288 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
1288 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
1289 | } |
|
1289 | } | |
1290 | else |
|
1290 | else | |
1291 | { |
|
1291 | { | |
1292 | parentZone->notifyMouseLeaveGraph(this); |
|
1292 | parentZone->notifyMouseLeaveGraph(this); | |
1293 | } |
|
1293 | } | |
1294 | } |
|
1294 | } | |
1295 |
|
1295 | |||
1296 | // Search for the selection zone under the mouse |
|
1296 | // Search for the selection zone under the mouse | |
1297 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); |
|
1297 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); | |
1298 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
1298 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
1299 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) |
|
1299 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) | |
1300 | { |
|
1300 | { | |
1301 |
|
1301 | |||
1302 | // Sets the appropriate cursor shape |
|
1302 | // Sets the appropriate cursor shape | |
1303 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
1303 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
1304 | setCursor(cursorShape); |
|
1304 | setCursor(cursorShape); | |
1305 |
|
1305 | |||
1306 | // Manages the hovered zone |
|
1306 | // Manages the hovered zone | |
1307 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) |
|
1307 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) | |
1308 | { |
|
1308 | { | |
1309 | if (impl->m_HoveredZone) |
|
1309 | if (impl->m_HoveredZone) | |
1310 | { |
|
1310 | { | |
1311 | impl->m_HoveredZone->setHovered(false); |
|
1311 | impl->m_HoveredZone->setHovered(false); | |
1312 | } |
|
1312 | } | |
1313 | selectionZoneItemUnderCursor->setHovered(true); |
|
1313 | selectionZoneItemUnderCursor->setHovered(true); | |
1314 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
1314 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
1315 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
1315 | plot().replot(QCustomPlot::rpQueuedReplot); | |
1316 | } |
|
1316 | } | |
1317 | } |
|
1317 | } | |
1318 | else |
|
1318 | else | |
1319 | { |
|
1319 | { | |
1320 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
1320 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
1321 | if (impl->m_HoveredZone) |
|
1321 | if (impl->m_HoveredZone) | |
1322 | { |
|
1322 | { | |
1323 | impl->m_HoveredZone->setHovered(false); |
|
1323 | impl->m_HoveredZone->setHovered(false); | |
1324 | impl->m_HoveredZone = nullptr; |
|
1324 | impl->m_HoveredZone = nullptr; | |
1325 | } |
|
1325 | } | |
1326 |
|
1326 | |||
1327 | setCursor(Qt::ArrowCursor); |
|
1327 | setCursor(Qt::ArrowCursor); | |
1328 | } |
|
1328 | } | |
1329 |
|
1329 | |||
1330 | impl->m_HasMovedMouse = true; |
|
1330 | impl->m_HasMovedMouse = true; | |
1331 | VisualizationDragWidget::mouseMoveEvent(event); |
|
1331 | VisualizationDragWidget::mouseMoveEvent(event); | |
1332 | } |
|
1332 | } | |
1333 |
|
1333 | |||
1334 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent* event) noexcept |
|
1334 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent* event) noexcept | |
1335 | { |
|
1335 | { | |
1336 | // Processes event only if the wheel occurs on axis rect |
|
1336 | // Processes event only if the wheel occurs on axis rect | |
1337 | if (!dynamic_cast<QCPAxisRect*>(impl->m_plot->layoutElementAt(event->posF()))) |
|
1337 | if (!dynamic_cast<QCPAxisRect*>(impl->m_plot->layoutElementAt(event->posF()))) | |
1338 | { |
|
1338 | { | |
1339 | return; |
|
1339 | return; | |
1340 | } |
|
1340 | } | |
1341 |
|
1341 | |||
1342 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
1342 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
1343 | if (value != 0) |
|
1343 | if (value != 0) | |
1344 | { |
|
1344 | { | |
1345 |
|
1345 | |||
1346 | auto direction = value > 0 ? 1.0 : -1.0; |
|
1346 | auto direction = value > 0 ? 1.0 : -1.0; | |
1347 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
1347 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
1348 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
1348 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
1349 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
1349 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
1350 |
|
1350 | |||
1351 | auto zoomOrientations = QFlags<Qt::Orientation> {}; |
|
1351 | auto zoomOrientations = QFlags<Qt::Orientation> {}; | |
1352 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
1352 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
1353 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
1353 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
1354 |
|
1354 | |||
1355 | impl->m_plot->axisRect()->setRangeZoom(zoomOrientations); |
|
1355 | impl->m_plot->axisRect()->setRangeZoom(zoomOrientations); | |
1356 |
|
1356 | |||
1357 | if (!isZoomX && !isZoomY) |
|
1357 | if (!isZoomX && !isZoomY) | |
1358 | { |
|
1358 | { | |
1359 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
1359 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
1360 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
1360 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
1361 |
|
1361 | |||
1362 | axis->setRange(axis->range() + diff); |
|
1362 | axis->setRange(axis->range() + diff); | |
1363 |
|
1363 | |||
1364 | if (plot().noAntialiasingOnDrag()) |
|
1364 | if (plot().noAntialiasingOnDrag()) | |
1365 | { |
|
1365 | { | |
1366 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
1366 | plot().setNotAntialiasedElements(QCP::aeAll); | |
1367 | } |
|
1367 | } | |
1368 |
|
1368 | |||
1369 | // plot().replot(QCustomPlot::rpQueuedReplot); |
|
1369 | // plot().replot(QCustomPlot::rpQueuedReplot); | |
1370 | } |
|
1370 | } | |
1371 | } |
|
1371 | } | |
1372 | } |
|
1372 | } | |
1373 |
|
1373 | |||
1374 | void VisualizationGraphWidget::onMousePress(QMouseEvent* event) noexcept |
|
1374 | void VisualizationGraphWidget::onMousePress(QMouseEvent* event) noexcept | |
1375 | { |
|
1375 | { | |
1376 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
1376 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
1377 | auto isSelectionZoneMode |
|
1377 | auto isSelectionZoneMode | |
1378 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
1378 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
1379 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
1379 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
1380 |
|
1380 | |||
1381 | if (!isDragDropClick && isLeftClick) |
|
1381 | if (!isDragDropClick && isLeftClick) | |
1382 | { |
|
1382 | { | |
1383 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) |
|
1383 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) | |
1384 | { |
|
1384 | { | |
1385 | // Starts a zoom box |
|
1385 | // Starts a zoom box | |
1386 | impl->startDrawingRect(event->pos()); |
|
1386 | impl->startDrawingRect(event->pos()); | |
1387 | } |
|
1387 | } | |
1388 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) |
|
1388 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) | |
1389 | { |
|
1389 | { | |
1390 | // Starts a new selection zone |
|
1390 | // Starts a new selection zone | |
1391 | auto zoneAtPos = impl->selectionZoneAt(event->pos()); |
|
1391 | auto zoneAtPos = impl->selectionZoneAt(event->pos()); | |
1392 | if (!zoneAtPos) |
|
1392 | if (!zoneAtPos) | |
1393 | { |
|
1393 | { | |
1394 | impl->startDrawingZone(event->pos()); |
|
1394 | impl->startDrawingZone(event->pos()); | |
1395 | } |
|
1395 | } | |
1396 | } |
|
1396 | } | |
1397 | } |
|
1397 | } | |
1398 |
|
1398 | |||
1399 |
|
1399 | |||
1400 | // Allows zone edition only in selection zone mode without drag&drop |
|
1400 | // Allows zone edition only in selection zone mode without drag&drop | |
1401 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
1401 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
1402 |
|
1402 | |||
1403 | // Selection / Deselection |
|
1403 | // Selection / Deselection | |
1404 | if (isSelectionZoneMode) |
|
1404 | if (isSelectionZoneMode) | |
1405 | { |
|
1405 | { | |
1406 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
1406 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
1407 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); |
|
1407 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); | |
1408 |
|
1408 | |||
1409 |
|
1409 | |||
1410 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
1410 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
1411 | && !isMultiSelectionClick) |
|
1411 | && !isMultiSelectionClick) | |
1412 | { |
|
1412 | { | |
1413 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1413 | parentVisualizationWidget()->selectionZoneManager().select( | |
1414 | { selectionZoneItemUnderCursor }); |
|
1414 | { selectionZoneItemUnderCursor }); | |
1415 | } |
|
1415 | } | |
1416 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) |
|
1416 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) | |
1417 | { |
|
1417 | { | |
1418 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
1418 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
1419 | } |
|
1419 | } | |
1420 | else |
|
1420 | else | |
1421 | { |
|
1421 | { | |
1422 | // No selection change |
|
1422 | // No selection change | |
1423 | } |
|
1423 | } | |
1424 |
|
1424 | |||
1425 | if (selectionZoneItemUnderCursor && isLeftClick) |
|
1425 | if (selectionZoneItemUnderCursor && isLeftClick) | |
1426 | { |
|
1426 | { | |
1427 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
1427 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
1428 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
1428 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
1429 | } |
|
1429 | } | |
1430 | } |
|
1430 | } | |
1431 |
|
1431 | |||
1432 |
|
1432 | |||
1433 | impl->m_HasMovedMouse = false; |
|
1433 | impl->m_HasMovedMouse = false; | |
1434 | VisualizationDragWidget::mousePressEvent(event); |
|
1434 | VisualizationDragWidget::mousePressEvent(event); | |
1435 | } |
|
1435 | } | |
1436 |
|
1436 | |||
1437 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent* event) noexcept |
|
1437 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent* event) noexcept | |
1438 | { |
|
1438 | { | |
1439 | if (impl->m_DrawingZoomRect) |
|
1439 | if (impl->m_DrawingZoomRect) | |
1440 | { |
|
1440 | { | |
1441 |
|
1441 | |||
1442 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
1442 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
1443 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
1443 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
1444 |
|
1444 | |||
1445 | auto newAxisXRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
1445 | auto newAxisXRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().x(), | |
1446 | impl->m_DrawingZoomRect->bottomRight->coords().x() }; |
|
1446 | impl->m_DrawingZoomRect->bottomRight->coords().x() }; | |
1447 |
|
1447 | |||
1448 | auto newAxisYRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
1448 | auto newAxisYRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().y(), | |
1449 | impl->m_DrawingZoomRect->bottomRight->coords().y() }; |
|
1449 | impl->m_DrawingZoomRect->bottomRight->coords().y() }; | |
1450 |
|
1450 | |||
1451 | impl->removeDrawingRect(); |
|
1451 | impl->removeDrawingRect(); | |
1452 |
|
1452 | |||
1453 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
1453 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
1454 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) |
|
1454 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) | |
1455 | { |
|
1455 | { | |
1456 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
1456 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
1457 | axisX->setRange(newAxisXRange); |
|
1457 | axisX->setRange(newAxisXRange); | |
1458 | axisY->setRange(newAxisYRange); |
|
1458 | axisY->setRange(newAxisYRange); | |
1459 |
|
1459 | |||
1460 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
1460 | plot().replot(QCustomPlot::rpQueuedReplot); | |
1461 | } |
|
1461 | } | |
1462 | } |
|
1462 | } | |
1463 |
|
1463 | |||
1464 | impl->endDrawingZone(); |
|
1464 | impl->endDrawingZone(); | |
1465 |
|
1465 | |||
1466 | // Selection / Deselection |
|
1466 | // Selection / Deselection | |
1467 | auto isSelectionZoneMode |
|
1467 | auto isSelectionZoneMode | |
1468 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
1468 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
1469 | if (isSelectionZoneMode) |
|
1469 | if (isSelectionZoneMode) | |
1470 | { |
|
1470 | { | |
1471 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
1471 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
1472 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); |
|
1472 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos()); | |
1473 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
1473 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
1474 | && !impl->m_HasMovedMouse) |
|
1474 | && !impl->m_HasMovedMouse) | |
1475 | { |
|
1475 | { | |
1476 |
|
1476 | |||
1477 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
1477 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
1478 | if (zonesUnderCursor.count() > 1) |
|
1478 | if (zonesUnderCursor.count() > 1) | |
1479 | { |
|
1479 | { | |
1480 | // There are multiple zones under the mouse. |
|
1480 | // There are multiple zones under the mouse. | |
1481 | // Performs the selection with a selection dialog. |
|
1481 | // Performs the selection with a selection dialog. | |
1482 | VisualizationMultiZoneSelectionDialog dialog { this }; |
|
1482 | VisualizationMultiZoneSelectionDialog dialog { this }; | |
1483 | dialog.setZones(zonesUnderCursor); |
|
1483 | dialog.setZones(zonesUnderCursor); | |
1484 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
1484 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
1485 | dialog.activateWindow(); |
|
1485 | dialog.activateWindow(); | |
1486 | dialog.raise(); |
|
1486 | dialog.raise(); | |
1487 | if (dialog.exec() == QDialog::Accepted) |
|
1487 | if (dialog.exec() == QDialog::Accepted) | |
1488 | { |
|
1488 | { | |
1489 | auto selection = dialog.selectedZones(); |
|
1489 | auto selection = dialog.selectedZones(); | |
1490 |
|
1490 | |||
1491 | if (!isMultiSelectionClick) |
|
1491 | if (!isMultiSelectionClick) | |
1492 | { |
|
1492 | { | |
1493 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
1493 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
1494 | } |
|
1494 | } | |
1495 |
|
1495 | |||
1496 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) |
|
1496 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) | |
1497 | { |
|
1497 | { | |
1498 | auto zone = it.key(); |
|
1498 | auto zone = it.key(); | |
1499 | auto isSelected = it.value(); |
|
1499 | auto isSelected = it.value(); | |
1500 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
1500 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
1501 | zone, isSelected); |
|
1501 | zone, isSelected); | |
1502 |
|
1502 | |||
1503 | if (isSelected) |
|
1503 | if (isSelected) | |
1504 | { |
|
1504 | { | |
1505 | // Puts the zone on top of the stack so it can be moved or resized |
|
1505 | // Puts the zone on top of the stack so it can be moved or resized | |
1506 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
1506 | impl->moveSelectionZoneOnTop(zone, plot()); | |
1507 | } |
|
1507 | } | |
1508 | } |
|
1508 | } | |
1509 | } |
|
1509 | } | |
1510 | } |
|
1510 | } | |
1511 | else |
|
1511 | else | |
1512 | { |
|
1512 | { | |
1513 | if (!isMultiSelectionClick) |
|
1513 | if (!isMultiSelectionClick) | |
1514 | { |
|
1514 | { | |
1515 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1515 | parentVisualizationWidget()->selectionZoneManager().select( | |
1516 | { selectionZoneItemUnderCursor }); |
|
1516 | { selectionZoneItemUnderCursor }); | |
1517 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
1517 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
1518 | } |
|
1518 | } | |
1519 | else |
|
1519 | else | |
1520 | { |
|
1520 | { | |
1521 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
1521 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
1522 | selectionZoneItemUnderCursor, |
|
1522 | selectionZoneItemUnderCursor, | |
1523 | !selectionZoneItemUnderCursor->selected() |
|
1523 | !selectionZoneItemUnderCursor->selected() | |
1524 | || event->button() == Qt::RightButton); |
|
1524 | || event->button() == Qt::RightButton); | |
1525 | } |
|
1525 | } | |
1526 | } |
|
1526 | } | |
1527 | } |
|
1527 | } | |
1528 | else |
|
1528 | else | |
1529 | { |
|
1529 | { | |
1530 | // No selection change |
|
1530 | // No selection change | |
1531 | } |
|
1531 | } | |
1532 | } |
|
1532 | } | |
1533 | } |
|
1533 | } | |
1534 |
|
1534 | |||
1535 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
1535 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
1536 | { |
|
1536 | { | |
1537 | auto graphRange = impl->m_plot->xAxis->range(); |
|
1537 | auto graphRange = impl->m_plot->xAxis->range(); | |
1538 | auto dateTime = DateTimeRange { graphRange.lower, graphRange.upper }; |
|
1538 | auto dateTime = DateTimeRange { graphRange.lower, graphRange.upper }; | |
1539 |
|
1539 | |||
1540 | for (auto& variableEntry : impl->m_VariableToPlotMultiMap) |
|
1540 | for (auto& variableEntry : impl->m_VariableToPlotMultiMap) | |
1541 | { |
|
1541 | { | |
1542 | auto variable = variableEntry.first; |
|
1542 | auto variable = variableEntry.first; | |
1543 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1543 | qCDebug(LOG_VisualizationGraphWidget()) | |
1544 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
1544 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
1545 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1545 | qCDebug(LOG_VisualizationGraphWidget()) | |
1546 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
1546 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
1547 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) |
|
1547 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) | |
1548 | { |
|
1548 | { | |
1549 | impl->updateData(variableEntry.second, variable, variable->range()); |
|
1549 | impl->updateData(variableEntry.second, variable, variable->range()); | |
1550 | } |
|
1550 | } | |
1551 | } |
|
1551 | } | |
1552 | } |
|
1552 | } | |
1553 |
|
1553 | |||
1554 | void VisualizationGraphWidget::onUpdateVarDisplaying( |
|
1554 | void VisualizationGraphWidget::onUpdateVarDisplaying( | |
1555 | std::shared_ptr<Variable2> variable, const DateTimeRange& range) |
|
1555 | std::shared_ptr<Variable2> variable, const DateTimeRange& range) | |
1556 | { |
|
1556 | { | |
1557 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
1557 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1558 | if (it != impl->m_VariableToPlotMultiMap.end()) |
|
1558 | if (it != impl->m_VariableToPlotMultiMap.end()) | |
1559 | { |
|
1559 | { | |
1560 | impl->updateData(it->second, variable, range); |
|
1560 | impl->updateData(it->second, variable, range); | |
1561 | } |
|
1561 | } | |
1562 | } |
|
1562 | } | |
1563 |
|
1563 | |||
1564 | void VisualizationGraphWidget::variableUpdated(QUuid id) |
|
1564 | void VisualizationGraphWidget::variableUpdated(QUuid id) | |
1565 | { |
|
1565 | { | |
1566 | for (auto& [var, plotables] : impl->m_VariableToPlotMultiMap) |
|
1566 | for (auto& [var, plotables] : impl->m_VariableToPlotMultiMap) | |
1567 | { |
|
1567 | { | |
1568 | if (var->ID() == id) |
|
1568 | if (var->ID() == id) | |
1569 | { |
|
1569 | { | |
1570 | impl->updateData(plotables, var, this->graphRange()); |
|
1570 | impl->updateData(plotables, var, this->graphRange()); | |
1571 | } |
|
1571 | } | |
1572 | } |
|
1572 | } | |
1573 | } |
|
1573 | } | |
1574 |
|
1574 | |||
1575 | void VisualizationGraphWidget::variableDeleted(const std::shared_ptr<Variable2>& variable) |
|
1575 | void VisualizationGraphWidget::variableDeleted(const std::shared_ptr<Variable2>& variable) | |
1576 | { |
|
1576 | { | |
1577 | this->removeVariable(variable); |
|
1577 | this->removeVariable(variable); | |
1578 | } |
|
1578 | } |
@@ -1,695 +1,635 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 |
|
2 | |||
3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
4 | #include "Visualization/QCustomPlotSynchronizer.h" |
|
4 | #include "Visualization/QCustomPlotSynchronizer.h" | |
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "Visualization/VisualizationWidget.h" |
|
6 | #include "Visualization/VisualizationWidget.h" | |
7 | #include "ui_VisualizationZoneWidget.h" |
|
7 | #include "ui_VisualizationZoneWidget.h" | |
8 |
|
8 | |||
9 | #include "MimeTypes/MimeTypes.h" |
|
9 | #include "MimeTypes/MimeTypes.h" | |
10 | #include "Common/VisualizationDef.h" |
|
10 | #include "Common/VisualizationDef.h" | |
11 |
|
11 | |||
12 | #include <Data/DateTimeRange.h> |
|
12 | #include <Data/DateTimeRange.h> | |
13 | #include <Data/DateTimeRangeHelper.h> |
|
13 | #include <Data/DateTimeRangeHelper.h> | |
14 | #include <DataSource/datasources.h> |
|
14 | #include <DataSource/datasources.h> | |
15 | #include <Time/TimeController.h> |
|
15 | #include <Time/TimeController.h> | |
16 | #include <Variable/Variable2.h> |
|
16 | #include <Variable/Variable2.h> | |
17 | #include <Variable/VariableController2.h> |
|
17 | #include <Variable/VariableController2.h> | |
18 |
|
18 | |||
19 | #include <Visualization/operations/FindVariableOperation.h> |
|
19 | #include <Visualization/operations/FindVariableOperation.h> | |
20 |
|
20 | |||
21 | #include <DragAndDrop/DragDropGuiController.h> |
|
21 | #include <DragAndDrop/DragDropGuiController.h> | |
22 | #include <QUuid> |
|
22 | #include <QUuid> | |
23 | #include <SqpApplication.h> |
|
23 | #include <SqpApplication.h> | |
24 | #include <cmath> |
|
24 | #include <cmath> | |
25 |
|
25 | |||
26 | #include <QLayout> |
|
26 | #include <QLayout> | |
27 | #include <QStyle> |
|
27 | #include <QStyle> | |
28 |
|
28 | |||
29 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
29 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
30 |
|
30 | |||
31 | namespace |
|
31 | namespace | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | /** |
|
34 | /** | |
35 | * Applies a function to all graphs of the zone represented by its layout |
|
35 | * Applies a function to all graphs of the zone represented by its layout | |
36 | * @param layout the layout that contains graphs |
|
36 | * @param layout the layout that contains graphs | |
37 | * @param fun the function to apply to each graph |
|
37 | * @param fun the function to apply to each graph | |
38 | */ |
|
38 | */ | |
39 | template <typename Fun> |
|
39 | template <typename Fun> | |
40 | void processGraphs(QLayout& layout, Fun fun) |
|
40 | void processGraphs(QLayout& layout, Fun fun) | |
41 | { |
|
41 | { | |
42 | for (auto i = 0; i < layout.count(); ++i) |
|
42 | for (auto i = 0; i < layout.count(); ++i) | |
43 | { |
|
43 | { | |
44 | if (auto item = layout.itemAt(i)) |
|
44 | if (auto item = layout.itemAt(i)) | |
45 | { |
|
45 | { | |
46 | if (auto visualizationGraphWidget |
|
46 | if (auto visualizationGraphWidget | |
47 | = qobject_cast<VisualizationGraphWidget*>(item->widget())) |
|
47 | = qobject_cast<VisualizationGraphWidget*>(item->widget())) | |
48 | { |
|
48 | { | |
49 | fun(*visualizationGraphWidget); |
|
49 | fun(*visualizationGraphWidget); | |
50 | } |
|
50 | } | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
55 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
56 | /// the zone |
|
56 | /// the zone | |
57 | QString defaultGraphName(QLayout& layout) |
|
57 | QString defaultGraphName(QLayout& layout) | |
58 | { |
|
58 | { | |
59 | QSet<QString> existingNames; |
|
59 | QSet<QString> existingNames; | |
60 | processGraphs( |
|
60 | processGraphs( | |
61 | layout, [&existingNames](auto& graphWidget) { existingNames.insert(graphWidget.name()); }); |
|
61 | layout, [&existingNames](auto& graphWidget) { existingNames.insert(graphWidget.name()); }); | |
62 |
|
62 | |||
63 | int zoneNum = 1; |
|
63 | int zoneNum = 1; | |
64 | QString name; |
|
64 | QString name; | |
65 | do |
|
65 | do | |
66 | { |
|
66 | { | |
67 | name = QObject::tr("Graph ").append(QString::number(zoneNum)); |
|
67 | name = QObject::tr("Graph ").append(QString::number(zoneNum)); | |
68 | ++zoneNum; |
|
68 | ++zoneNum; | |
69 | } while (existingNames.contains(name)); |
|
69 | } while (existingNames.contains(name)); | |
70 |
|
70 | |||
71 | return name; |
|
71 | return name; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | } // namespace |
|
74 | } // namespace | |
75 |
|
75 | |||
76 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate |
|
76 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate | |
77 | { |
|
77 | { | |
78 |
|
78 | |||
79 | explicit VisualizationZoneWidgetPrivate() |
|
79 | explicit VisualizationZoneWidgetPrivate() | |
80 | : m_SynchronisationGroupId { QUuid::createUuid() } |
|
80 | : m_SynchronisationGroupId { QUuid::createUuid() } | |
81 | , m_Synchronizer { std::make_unique<QCustomPlotSynchronizer>() } |
|
81 | , m_Synchronizer { std::make_unique<QCustomPlotSynchronizer>() } | |
82 | { |
|
82 | { | |
83 | } |
|
83 | } | |
84 | QUuid m_SynchronisationGroupId; |
|
84 | QUuid m_SynchronisationGroupId; | |
85 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; |
|
85 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; | |
86 |
|
86 | |||
87 | void dropGraph(int index, VisualizationZoneWidget* zoneWidget); |
|
87 | void dropGraph(int index, VisualizationZoneWidget* zoneWidget); | |
88 | void dropVariables(const std::vector<std::shared_ptr<Variable2>>& variables, int index, |
|
88 | void dropVariables(const std::vector<std::shared_ptr<Variable2>>& variables, int index, | |
89 | VisualizationZoneWidget* zoneWidget); |
|
89 | VisualizationZoneWidget* zoneWidget); | |
90 | void dropProducts( |
|
90 | void dropProducts( | |
91 | const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget); |
|
91 | const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget); | |
92 | }; |
|
92 | }; | |
93 |
|
93 | |||
94 | VisualizationZoneWidget::VisualizationZoneWidget(const QString& name, QWidget* parent) |
|
94 | VisualizationZoneWidget::VisualizationZoneWidget(const QString& name, QWidget* parent) | |
95 | : VisualizationDragWidget { parent } |
|
95 | : VisualizationDragWidget { parent } | |
96 | , ui { new Ui::VisualizationZoneWidget } |
|
96 | , ui { new Ui::VisualizationZoneWidget } | |
97 | , impl { spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>() } |
|
97 | , impl { spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>() } | |
98 | { |
|
98 | { | |
99 | ui->setupUi(this); |
|
99 | ui->setupUi(this); | |
100 |
|
100 | |||
101 | ui->zoneNameLabel->setText(name); |
|
101 | ui->zoneNameLabel->setText(name); | |
102 |
|
102 | |||
103 | ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Graph); |
|
103 | ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Graph); | |
104 | ui->dragDropContainer->setMimeType( |
|
104 | ui->dragDropContainer->setMimeType( | |
105 | MIME::MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); |
|
105 | MIME::MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); | |
106 | ui->dragDropContainer->setMimeType( |
|
106 | ui->dragDropContainer->setMimeType( | |
107 | MIME::MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); |
|
107 | MIME::MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); | |
108 | ui->dragDropContainer->setMimeType( |
|
108 | ui->dragDropContainer->setMimeType( | |
109 | MIME::MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); |
|
109 | MIME::MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); | |
110 | ui->dragDropContainer->setMimeType( |
|
110 | ui->dragDropContainer->setMimeType( | |
111 | MIME::MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged); |
|
111 | MIME::MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged); | |
112 | ui->dragDropContainer->setMimeType( |
|
112 | ui->dragDropContainer->setMimeType( | |
113 | MIME::MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden); |
|
113 | MIME::MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden); | |
114 | ui->dragDropContainer->setMimeType( |
|
114 | ui->dragDropContainer->setMimeType( | |
115 | MIME::MIME_TYPE_SELECTION_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden); |
|
115 | MIME::MIME_TYPE_SELECTION_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden); | |
116 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { |
|
116 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { | |
117 | return sqpApp->dragDropGuiController().checkMimeDataForVisualization( |
|
117 | return sqpApp->dragDropGuiController().checkMimeDataForVisualization( | |
118 | mimeData, ui->dragDropContainer); |
|
118 | mimeData, ui->dragDropContainer); | |
119 | }); |
|
119 | }); | |
120 |
|
120 | |||
121 | auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) { |
|
121 | auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) { | |
122 | if (!mimeData) |
|
122 | if (!mimeData) | |
123 | { |
|
123 | { | |
124 | return false; |
|
124 | return false; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) |
|
127 | if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) | |
128 | { |
|
128 | { | |
129 | auto variables = sqpApp->variableController().variables( |
|
129 | auto variables = sqpApp->variableController().variables( | |
130 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); |
|
130 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); | |
131 |
|
131 | |||
132 | if (variables.size() != 1) |
|
132 | if (variables.size() != 1) | |
133 | { |
|
133 | { | |
134 | return false; |
|
134 | return false; | |
135 | } |
|
135 | } | |
136 | auto variable = variables.front(); |
|
136 | auto variable = variables.front(); | |
137 |
|
137 | |||
138 | if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget*>(dragWidget)) |
|
138 | if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget*>(dragWidget)) | |
139 | { |
|
139 | { | |
140 | return graphWidget->canDrop(*variable); |
|
140 | return graphWidget->canDrop(*variable); | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | return true; |
|
144 | return true; | |
145 | }; |
|
145 | }; | |
146 | ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun); |
|
146 | ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun); | |
147 |
|
147 | |||
148 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, |
|
148 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
149 | &VisualizationZoneWidget::dropMimeData); |
|
149 | &VisualizationZoneWidget::dropMimeData); | |
150 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, |
|
150 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, | |
151 | &VisualizationZoneWidget::dropMimeDataOnGraph); |
|
151 | &VisualizationZoneWidget::dropMimeDataOnGraph); | |
152 |
|
152 | |||
153 | // 'Close' options : widget is deleted when closed |
|
153 | // 'Close' options : widget is deleted when closed | |
154 | setAttribute(Qt::WA_DeleteOnClose); |
|
154 | setAttribute(Qt::WA_DeleteOnClose); | |
155 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
155 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
156 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
156 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
157 |
|
157 | |||
158 | // Synchronisation id |
|
158 | // Synchronisation id | |
159 | // QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
159 | // QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", | |
160 | // Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
160 | // Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
163 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
164 | { |
|
164 | { | |
165 | delete ui; |
|
165 | delete ui; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void VisualizationZoneWidget::setZoneRange(const DateTimeRange& range) |
|
168 | void VisualizationZoneWidget::setZoneRange(const DateTimeRange& range) | |
169 | { |
|
169 | { | |
170 | if (auto graph = firstGraph()) |
|
170 | if (auto graph = firstGraph()) | |
171 | { |
|
171 | { | |
172 | graph->setGraphRange(range); |
|
172 | graph->setGraphRange(range); | |
173 | } |
|
173 | } | |
174 | else |
|
174 | else | |
175 | { |
|
175 | { | |
176 | qCWarning(LOG_VisualizationZoneWidget()) |
|
176 | qCWarning(LOG_VisualizationZoneWidget()) | |
177 | << tr("setZoneRange:Cannot set the range of an empty zone."); |
|
177 | << tr("setZoneRange:Cannot set the range of an empty zone."); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget* graphWidget) |
|
181 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget* graphWidget) | |
182 | { |
|
182 | { | |
183 | // Synchronize new graph with others in the zone |
|
183 | // Synchronize new graph with others in the zone | |
184 | // impl->m_Synchronizer->addGraph(*graphWidget); |
|
184 | // impl->m_Synchronizer->addGraph(*graphWidget); | |
185 |
|
185 | |||
186 | // ui->dragDropContainer->addDragWidget(graphWidget); |
|
186 | // ui->dragDropContainer->addDragWidget(graphWidget); | |
187 | insertGraph(0, graphWidget); |
|
187 | insertGraph(0, graphWidget); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget* graphWidget) |
|
190 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget* graphWidget) | |
191 | { |
|
191 | { | |
192 | DEPRECATE( |
|
192 | DEPRECATE( | |
193 | auto layout = ui->dragDropContainer->layout(); for (int i = 0; i < layout->count(); i++) { |
|
193 | auto layout = ui->dragDropContainer->layout(); for (int i = 0; i < layout->count(); i++) { | |
194 | auto graph = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(i)->widget()); |
|
194 | auto graph = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(i)->widget()); | |
195 | connect(graphWidget, &VisualizationGraphWidget::setrange_sig, graph, |
|
195 | connect(graphWidget, &VisualizationGraphWidget::setrange_sig, graph, | |
196 | &VisualizationGraphWidget::setGraphRange); |
|
196 | &VisualizationGraphWidget::setGraphRange); | |
197 | connect(graph, &VisualizationGraphWidget::setrange_sig, graphWidget, |
|
197 | connect(graph, &VisualizationGraphWidget::setrange_sig, graphWidget, | |
198 | &VisualizationGraphWidget::setGraphRange); |
|
198 | &VisualizationGraphWidget::setGraphRange); | |
199 | } if (auto graph = firstGraph()) { graphWidget->setGraphRange(graph->graphRange(), true); }) |
|
199 | } if (auto graph = firstGraph()) { graphWidget->setGraphRange(graph->graphRange(), true); }) | |
200 |
|
200 | |||
201 | // Synchronize new graph with others in the zone |
|
201 | // Synchronize new graph with others in the zone | |
202 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
202 | impl->m_Synchronizer->addGraph(*graphWidget); | |
203 |
|
203 | |||
204 | ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
204 | ui->dragDropContainer->insertDragWidget(index, graphWidget); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph(std::shared_ptr<Variable2> variable) |
|
207 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph(std::shared_ptr<Variable2> variable) | |
208 | { |
|
208 | { | |
209 | return createGraph(variable, -1); |
|
209 | return createGraph(variable, -1); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph( |
|
212 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph( | |
213 | std::shared_ptr<Variable2> variable, int index) |
|
213 | std::shared_ptr<Variable2> variable, int index) | |
214 | { |
|
214 | { | |
215 | auto graphWidget |
|
215 | auto graphWidget | |
216 | = new VisualizationGraphWidget { defaultGraphName(*ui->dragDropContainer->layout()), this }; |
|
216 | = new VisualizationGraphWidget { defaultGraphName(*ui->dragDropContainer->layout()), this }; | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | // Set graph properties |
|
219 | // Set graph properties | |
220 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
220 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | |
221 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
221 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | |
222 |
|
222 | |||
223 |
|
||||
224 | // Lambda to synchronize zone widget |
|
|||
225 | // auto synchronizeZoneWidget = [this, graphWidget](const DateTimeRange &graphRange, |
|
|||
226 | // const DateTimeRange &oldGraphRange) { |
|
|||
227 |
|
||||
228 | // auto zoomType = DateTimeRangeHelper::getTransformationType(oldGraphRange, graphRange); |
|
|||
229 | // auto frameLayout = ui->dragDropContainer->layout(); |
|
|||
230 | // for (auto i = 0; i < frameLayout->count(); ++i) { |
|
|||
231 | // auto graphChild |
|
|||
232 | // = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
|||
233 | // if (graphChild && (graphChild != graphWidget)) { |
|
|||
234 |
|
||||
235 | // auto graphChildRange = graphChild->graphRange(); |
|
|||
236 | // switch (zoomType) { |
|
|||
237 | // case TransformationType::ZoomIn: { |
|
|||
238 | // auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
|||
239 | // auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
|||
240 | // graphChildRange.m_TStart += deltaLeft; |
|
|||
241 | // graphChildRange.m_TEnd -= deltaRight; |
|
|||
242 | // break; |
|
|||
243 | // } |
|
|||
244 |
|
||||
245 | // case TransformationType::ZoomOut: { |
|
|||
246 | // auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
|||
247 | // auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
|||
248 | // graphChildRange.m_TStart -= deltaLeft; |
|
|||
249 | // graphChildRange.m_TEnd += deltaRight; |
|
|||
250 | // break; |
|
|||
251 | // } |
|
|||
252 | // case TransformationType::PanRight: { |
|
|||
253 | // auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
|||
254 | // auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
|||
255 | // graphChildRange.m_TStart += deltaLeft; |
|
|||
256 | // graphChildRange.m_TEnd += deltaRight; |
|
|||
257 | // break; |
|
|||
258 | // } |
|
|||
259 | // case TransformationType::PanLeft: { |
|
|||
260 | // auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
|||
261 | // auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
|||
262 | // graphChildRange.m_TStart -= deltaLeft; |
|
|||
263 | // graphChildRange.m_TEnd -= deltaRight; |
|
|||
264 | // break; |
|
|||
265 | // } |
|
|||
266 | // case TransformationType::Unknown: { |
|
|||
267 | // break; |
|
|||
268 | // } |
|
|||
269 | // default: |
|
|||
270 | // qCCritical(LOG_VisualizationZoneWidget()) |
|
|||
271 | // << tr("Impossible to synchronize: zoom type not take into |
|
|||
272 | // account"); |
|
|||
273 | // // No action |
|
|||
274 | // break; |
|
|||
275 | // } |
|
|||
276 | // graphChild->setFlags(GraphFlag::DisableAll); |
|
|||
277 | // graphChild->setGraphRange(graphChildRange, true); |
|
|||
278 | // graphChild->setFlags(GraphFlag::EnableAll); |
|
|||
279 | // } |
|
|||
280 | // } |
|
|||
281 | // }; |
|
|||
282 |
|
||||
283 | // connection for synchronization |
|
223 | // connection for synchronization | |
284 | // connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
224 | // connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
285 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
225 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, | |
286 | &VisualizationZoneWidget::onVariableAdded); |
|
226 | &VisualizationZoneWidget::onVariableAdded); | |
287 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, |
|
227 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, | |
288 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); |
|
228 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); | |
289 |
|
229 | |||
290 | auto range = DateTimeRange {}; |
|
230 | auto range = DateTimeRange {}; | |
291 | if (auto firstGraph = this->firstGraph()) |
|
231 | if (auto firstGraph = this->firstGraph()) | |
292 | { |
|
232 | { | |
293 | // Case of a new graph in a existant zone |
|
233 | // Case of a new graph in a existant zone | |
294 | range = firstGraph->graphRange(); |
|
234 | range = firstGraph->graphRange(); | |
295 | } |
|
235 | } | |
296 | else |
|
236 | else | |
297 | { |
|
237 | { | |
298 | // Case of a new graph as the first of the zone |
|
238 | // Case of a new graph as the first of the zone | |
299 | range = variable->range(); |
|
239 | range = variable->range(); | |
300 | } |
|
240 | } | |
301 |
|
241 | |||
302 | this->insertGraph(index, graphWidget); |
|
242 | this->insertGraph(index, graphWidget); | |
303 |
|
243 | |||
304 | graphWidget->addVariable(variable, range); |
|
244 | graphWidget->addVariable(variable, range); | |
305 | graphWidget->setYRange(variable); |
|
245 | graphWidget->setYRange(variable); | |
306 |
|
246 | |||
307 | return graphWidget; |
|
247 | return graphWidget; | |
308 | } |
|
248 | } | |
309 |
|
249 | |||
310 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph( |
|
250 | VisualizationGraphWidget* VisualizationZoneWidget::createGraph( | |
311 | const std::vector<std::shared_ptr<Variable2>> variables, int index) |
|
251 | const std::vector<std::shared_ptr<Variable2>> variables, int index) | |
312 | { |
|
252 | { | |
313 | if (variables.empty()) |
|
253 | if (variables.empty()) | |
314 | { |
|
254 | { | |
315 | return nullptr; |
|
255 | return nullptr; | |
316 | } |
|
256 | } | |
317 |
|
257 | |||
318 | auto graphWidget = createGraph(variables.front(), index); |
|
258 | auto graphWidget = createGraph(variables.front(), index); | |
319 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) |
|
259 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) | |
320 | { |
|
260 | { | |
321 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); |
|
261 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); | |
322 | } |
|
262 | } | |
323 |
|
263 | |||
324 | return graphWidget; |
|
264 | return graphWidget; | |
325 | } |
|
265 | } | |
326 |
|
266 | |||
327 | VisualizationGraphWidget* VisualizationZoneWidget::firstGraph() const |
|
267 | VisualizationGraphWidget* VisualizationZoneWidget::firstGraph() const | |
328 | { |
|
268 | { | |
329 | VisualizationGraphWidget* firstGraph = nullptr; |
|
269 | VisualizationGraphWidget* firstGraph = nullptr; | |
330 | auto layout = ui->dragDropContainer->layout(); |
|
270 | auto layout = ui->dragDropContainer->layout(); | |
331 | if (layout->count() > 0) |
|
271 | if (layout->count() > 0) | |
332 | { |
|
272 | { | |
333 | if (auto visualizationGraphWidget |
|
273 | if (auto visualizationGraphWidget | |
334 | = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget())) |
|
274 | = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget())) | |
335 | { |
|
275 | { | |
336 | firstGraph = visualizationGraphWidget; |
|
276 | firstGraph = visualizationGraphWidget; | |
337 | } |
|
277 | } | |
338 | } |
|
278 | } | |
339 |
|
279 | |||
340 | return firstGraph; |
|
280 | return firstGraph; | |
341 | } |
|
281 | } | |
342 |
|
282 | |||
343 | void VisualizationZoneWidget::closeAllGraphs() |
|
283 | void VisualizationZoneWidget::closeAllGraphs() | |
344 | { |
|
284 | { | |
345 | processGraphs(*ui->dragDropContainer->layout(), |
|
285 | processGraphs(*ui->dragDropContainer->layout(), | |
346 | [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); }); |
|
286 | [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); }); | |
347 | } |
|
287 | } | |
348 |
|
288 | |||
349 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor* visitor) |
|
289 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor* visitor) | |
350 | { |
|
290 | { | |
351 | if (visitor) |
|
291 | if (visitor) | |
352 | { |
|
292 | { | |
353 | visitor->visitEnter(this); |
|
293 | visitor->visitEnter(this); | |
354 |
|
294 | |||
355 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
295 | // Apply visitor to graph children: widgets different from graphs are not visited (no | |
356 | // action) |
|
296 | // action) | |
357 | processGraphs(*ui->dragDropContainer->layout(), |
|
297 | processGraphs(*ui->dragDropContainer->layout(), | |
358 | [visitor](VisualizationGraphWidget& graphWidget) { graphWidget.accept(visitor); }); |
|
298 | [visitor](VisualizationGraphWidget& graphWidget) { graphWidget.accept(visitor); }); | |
359 |
|
299 | |||
360 | visitor->visitLeave(this); |
|
300 | visitor->visitLeave(this); | |
361 | } |
|
301 | } | |
362 | else |
|
302 | else | |
363 | { |
|
303 | { | |
364 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
304 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
365 | } |
|
305 | } | |
366 | } |
|
306 | } | |
367 |
|
307 | |||
368 | bool VisualizationZoneWidget::canDrop(Variable2& variable) const |
|
308 | bool VisualizationZoneWidget::canDrop(Variable2& variable) const | |
369 | { |
|
309 | { | |
370 | // A tab can always accomodate a variable |
|
310 | // A tab can always accomodate a variable | |
371 | Q_UNUSED(variable); |
|
311 | Q_UNUSED(variable); | |
372 | return true; |
|
312 | return true; | |
373 | } |
|
313 | } | |
374 |
|
314 | |||
375 | bool VisualizationZoneWidget::contains(Variable2& variable) const |
|
315 | bool VisualizationZoneWidget::contains(Variable2& variable) const | |
376 | { |
|
316 | { | |
377 | Q_UNUSED(variable); |
|
317 | Q_UNUSED(variable); | |
378 | return false; |
|
318 | return false; | |
379 | } |
|
319 | } | |
380 |
|
320 | |||
381 | QString VisualizationZoneWidget::name() const |
|
321 | QString VisualizationZoneWidget::name() const | |
382 | { |
|
322 | { | |
383 | return ui->zoneNameLabel->text(); |
|
323 | return ui->zoneNameLabel->text(); | |
384 | } |
|
324 | } | |
385 |
|
325 | |||
386 | QMimeData* VisualizationZoneWidget::mimeData(const QPoint& position) const |
|
326 | QMimeData* VisualizationZoneWidget::mimeData(const QPoint& position) const | |
387 | { |
|
327 | { | |
388 | Q_UNUSED(position); |
|
328 | Q_UNUSED(position); | |
389 |
|
329 | |||
390 | auto mimeData = new QMimeData; |
|
330 | auto mimeData = new QMimeData; | |
391 | mimeData->setData(MIME::MIME_TYPE_ZONE, QByteArray {}); |
|
331 | mimeData->setData(MIME::MIME_TYPE_ZONE, QByteArray {}); | |
392 |
|
332 | |||
393 | if (auto firstGraph = this->firstGraph()) |
|
333 | if (auto firstGraph = this->firstGraph()) | |
394 | { |
|
334 | { | |
395 | auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange()); |
|
335 | auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange()); | |
396 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData); |
|
336 | mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData); | |
397 | } |
|
337 | } | |
398 |
|
338 | |||
399 | return mimeData; |
|
339 | return mimeData; | |
400 | } |
|
340 | } | |
401 |
|
341 | |||
402 | bool VisualizationZoneWidget::isDragAllowed() const |
|
342 | bool VisualizationZoneWidget::isDragAllowed() const | |
403 | { |
|
343 | { | |
404 | return true; |
|
344 | return true; | |
405 | } |
|
345 | } | |
406 |
|
346 | |||
407 | void VisualizationZoneWidget::notifyMouseMoveInGraph(const QPointF& graphPosition, |
|
347 | void VisualizationZoneWidget::notifyMouseMoveInGraph(const QPointF& graphPosition, | |
408 | const QPointF& plotPosition, VisualizationGraphWidget* graphWidget) |
|
348 | const QPointF& plotPosition, VisualizationGraphWidget* graphWidget) | |
409 | { |
|
349 | { | |
410 | processGraphs(*ui->dragDropContainer->layout(), |
|
350 | processGraphs(*ui->dragDropContainer->layout(), | |
411 | [&graphPosition, &plotPosition, &graphWidget](VisualizationGraphWidget& processedGraph) { |
|
351 | [&graphPosition, &plotPosition, &graphWidget](VisualizationGraphWidget& processedGraph) { | |
412 | switch (sqpApp->plotsCursorMode()) |
|
352 | switch (sqpApp->plotsCursorMode()) | |
413 | { |
|
353 | { | |
414 | case SqpApplication::PlotsCursorMode::Vertical: |
|
354 | case SqpApplication::PlotsCursorMode::Vertical: | |
415 | processedGraph.removeHorizontalCursor(); |
|
355 | processedGraph.removeHorizontalCursor(); | |
416 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); |
|
356 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); | |
417 | break; |
|
357 | break; | |
418 | case SqpApplication::PlotsCursorMode::Temporal: |
|
358 | case SqpApplication::PlotsCursorMode::Temporal: | |
419 | processedGraph.addVerticalCursor(plotPosition.x()); |
|
359 | processedGraph.addVerticalCursor(plotPosition.x()); | |
420 | processedGraph.removeHorizontalCursor(); |
|
360 | processedGraph.removeHorizontalCursor(); | |
421 | break; |
|
361 | break; | |
422 | case SqpApplication::PlotsCursorMode::Horizontal: |
|
362 | case SqpApplication::PlotsCursorMode::Horizontal: | |
423 | processedGraph.removeVerticalCursor(); |
|
363 | processedGraph.removeVerticalCursor(); | |
424 | if (&processedGraph == graphWidget) |
|
364 | if (&processedGraph == graphWidget) | |
425 | { |
|
365 | { | |
426 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); |
|
366 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); | |
427 | } |
|
367 | } | |
428 | else |
|
368 | else | |
429 | { |
|
369 | { | |
430 | processedGraph.removeHorizontalCursor(); |
|
370 | processedGraph.removeHorizontalCursor(); | |
431 | } |
|
371 | } | |
432 | break; |
|
372 | break; | |
433 | case SqpApplication::PlotsCursorMode::Cross: |
|
373 | case SqpApplication::PlotsCursorMode::Cross: | |
434 | if (&processedGraph == graphWidget) |
|
374 | if (&processedGraph == graphWidget) | |
435 | { |
|
375 | { | |
436 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); |
|
376 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); | |
437 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); |
|
377 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); | |
438 | } |
|
378 | } | |
439 | else |
|
379 | else | |
440 | { |
|
380 | { | |
441 | processedGraph.removeHorizontalCursor(); |
|
381 | processedGraph.removeHorizontalCursor(); | |
442 | processedGraph.removeVerticalCursor(); |
|
382 | processedGraph.removeVerticalCursor(); | |
443 | } |
|
383 | } | |
444 | break; |
|
384 | break; | |
445 | case SqpApplication::PlotsCursorMode::NoCursor: |
|
385 | case SqpApplication::PlotsCursorMode::NoCursor: | |
446 | processedGraph.removeHorizontalCursor(); |
|
386 | processedGraph.removeHorizontalCursor(); | |
447 | processedGraph.removeVerticalCursor(); |
|
387 | processedGraph.removeVerticalCursor(); | |
448 | break; |
|
388 | break; | |
449 | } |
|
389 | } | |
450 | }); |
|
390 | }); | |
451 | } |
|
391 | } | |
452 |
|
392 | |||
453 | void VisualizationZoneWidget::notifyMouseLeaveGraph(VisualizationGraphWidget* graphWidget) |
|
393 | void VisualizationZoneWidget::notifyMouseLeaveGraph(VisualizationGraphWidget* graphWidget) | |
454 | { |
|
394 | { | |
455 | processGraphs(*ui->dragDropContainer->layout(), [](VisualizationGraphWidget& processedGraph) { |
|
395 | processGraphs(*ui->dragDropContainer->layout(), [](VisualizationGraphWidget& processedGraph) { | |
456 | processedGraph.removeHorizontalCursor(); |
|
396 | processedGraph.removeHorizontalCursor(); | |
457 | processedGraph.removeVerticalCursor(); |
|
397 | processedGraph.removeVerticalCursor(); | |
458 | }); |
|
398 | }); | |
459 | } |
|
399 | } | |
460 |
|
400 | |||
461 | void VisualizationZoneWidget::closeEvent(QCloseEvent* event) |
|
401 | void VisualizationZoneWidget::closeEvent(QCloseEvent* event) | |
462 | { |
|
402 | { | |
463 | // Closes graphs in the zone |
|
403 | // Closes graphs in the zone | |
464 | processGraphs(*ui->dragDropContainer->layout(), |
|
404 | processGraphs(*ui->dragDropContainer->layout(), | |
465 | [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); }); |
|
405 | [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); }); | |
466 |
|
406 | |||
467 | // Delete synchronization group from variable controller |
|
407 | // Delete synchronization group from variable controller | |
468 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", |
|
408 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", | |
469 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
409 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
470 |
|
410 | |||
471 | QWidget::closeEvent(event); |
|
411 | QWidget::closeEvent(event); | |
472 | } |
|
412 | } | |
473 |
|
413 | |||
474 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable2> variable) |
|
414 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable2> variable) | |
475 | { |
|
415 | { | |
476 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
416 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", | |
477 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable2>, variable), |
|
417 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable2>, variable), | |
478 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
418 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
479 | } |
|
419 | } | |
480 |
|
420 | |||
481 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable2> variable) |
|
421 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable2> variable) | |
482 | { |
|
422 | { | |
483 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, |
|
423 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, | |
484 | Q_ARG(std::shared_ptr<Variable2>, variable), Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
424 | Q_ARG(std::shared_ptr<Variable2>, variable), Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
485 | } |
|
425 | } | |
486 |
|
426 | |||
487 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData* mimeData) |
|
427 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData* mimeData) | |
488 | { |
|
428 | { | |
489 | if (mimeData->hasFormat(MIME::MIME_TYPE_GRAPH)) |
|
429 | if (mimeData->hasFormat(MIME::MIME_TYPE_GRAPH)) | |
490 | { |
|
430 | { | |
491 | impl->dropGraph(index, this); |
|
431 | impl->dropGraph(index, this); | |
492 | } |
|
432 | } | |
493 | else if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) |
|
433 | else if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) | |
494 | { |
|
434 | { | |
495 | auto variables = sqpApp->variableController().variables( |
|
435 | auto variables = sqpApp->variableController().variables( | |
496 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); |
|
436 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); | |
497 | impl->dropVariables(variables, index, this); |
|
437 | impl->dropVariables(variables, index, this); | |
498 | } |
|
438 | } | |
499 | else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) |
|
439 | else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) | |
500 | { |
|
440 | { | |
501 | auto products = MIME::decode( |
|
441 | auto products = MIME::decode( | |
502 | mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); |
|
442 | mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); | |
503 | impl->dropProducts(products, index, this); |
|
443 | impl->dropProducts(products, index, this); | |
504 | } |
|
444 | } | |
505 | else |
|
445 | else | |
506 | { |
|
446 | { | |
507 | qCWarning(LOG_VisualizationZoneWidget()) |
|
447 | qCWarning(LOG_VisualizationZoneWidget()) | |
508 | << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received."); |
|
448 | << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received."); | |
509 | } |
|
449 | } | |
510 | } |
|
450 | } | |
511 |
|
451 | |||
512 | void VisualizationZoneWidget::dropMimeDataOnGraph( |
|
452 | void VisualizationZoneWidget::dropMimeDataOnGraph( | |
513 | VisualizationDragWidget* dragWidget, const QMimeData* mimeData) |
|
453 | VisualizationDragWidget* dragWidget, const QMimeData* mimeData) | |
514 | { |
|
454 | { | |
515 | auto graphWidget = qobject_cast<VisualizationGraphWidget*>(dragWidget); |
|
455 | auto graphWidget = qobject_cast<VisualizationGraphWidget*>(dragWidget); | |
516 | if (!graphWidget) |
|
456 | if (!graphWidget) | |
517 | { |
|
457 | { | |
518 | qCWarning(LOG_VisualizationZoneWidget()) |
|
458 | qCWarning(LOG_VisualizationZoneWidget()) | |
519 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, " |
|
459 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, " | |
520 | "drop aborted"); |
|
460 | "drop aborted"); | |
521 | Q_ASSERT(false); |
|
461 | Q_ASSERT(false); | |
522 | return; |
|
462 | return; | |
523 | } |
|
463 | } | |
524 |
|
464 | |||
525 | if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) |
|
465 | if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) | |
526 | { |
|
466 | { | |
527 | auto variables = sqpApp->variableController().variables( |
|
467 | auto variables = sqpApp->variableController().variables( | |
528 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); |
|
468 | Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); | |
529 | for (const auto& var : variables) |
|
469 | for (const auto& var : variables) | |
530 | { |
|
470 | { | |
531 | graphWidget->addVariable(var, graphWidget->graphRange()); |
|
471 | graphWidget->addVariable(var, graphWidget->graphRange()); | |
532 | } |
|
472 | } | |
533 | } |
|
473 | } | |
534 | else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) |
|
474 | else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) | |
535 | { |
|
475 | { | |
536 | auto products = MIME::decode( |
|
476 | auto products = MIME::decode( | |
537 | mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); |
|
477 | mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); | |
538 |
|
478 | |||
539 | auto context = new QObject { this }; |
|
479 | auto context = new QObject { this }; | |
540 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE)); |
|
480 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE)); | |
541 | // BTW this is really dangerous, this assumes the next created variable will be this one... |
|
481 | // BTW this is really dangerous, this assumes the next created variable will be this one... | |
542 | connect(&sqpApp->variableController(), &VariableController2::variableAdded, context, |
|
482 | connect(&sqpApp->variableController(), &VariableController2::variableAdded, context, | |
543 | [this, graphWidget, context, range](auto variable) { |
|
483 | [this, graphWidget, context, range](auto variable) { | |
544 | if (sqpApp->variableController().isReady(variable)) |
|
484 | if (sqpApp->variableController().isReady(variable)) | |
545 | { |
|
485 | { | |
546 | graphWidget->addVariable(variable, range); |
|
486 | graphWidget->addVariable(variable, range); | |
547 | delete context; |
|
487 | delete context; | |
548 | } |
|
488 | } | |
549 | else |
|
489 | else | |
550 | { |
|
490 | { | |
551 | // -> this is pure insanity! this is a workaround to make a bad design work |
|
491 | // -> this is pure insanity! this is a workaround to make a bad design work | |
552 | QObject::connect(variable.get(), &Variable2::updated, context, |
|
492 | QObject::connect(variable.get(), &Variable2::updated, context, | |
553 | [graphWidget, context, range, variable]() { |
|
493 | [graphWidget, context, range, variable]() { | |
554 | graphWidget->addVariable(variable, range); |
|
494 | graphWidget->addVariable(variable, range); | |
555 | delete context; |
|
495 | delete context; | |
556 | }); |
|
496 | }); | |
557 | } |
|
497 | } | |
558 | }, |
|
498 | }, | |
559 | Qt::QueuedConnection); |
|
499 | Qt::QueuedConnection); | |
560 |
|
500 | |||
561 | auto productPath = products.first().toString(); |
|
501 | auto productPath = products.first().toString(); | |
562 | QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable", |
|
502 | QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable", | |
563 | Qt::QueuedConnection, Q_ARG(QString, productPath)); |
|
503 | Qt::QueuedConnection, Q_ARG(QString, productPath)); | |
564 | } |
|
504 | } | |
565 | else if (mimeData->hasFormat(MIME::MIME_TYPE_TIME_RANGE)) |
|
505 | else if (mimeData->hasFormat(MIME::MIME_TYPE_TIME_RANGE)) | |
566 | { |
|
506 | { | |
567 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE)); |
|
507 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE)); | |
568 | graphWidget->setGraphRange(range, true, true); |
|
508 | graphWidget->setGraphRange(range, true, true); | |
569 | } |
|
509 | } | |
570 | else |
|
510 | else | |
571 | { |
|
511 | { | |
572 | qCWarning(LOG_VisualizationZoneWidget()) |
|
512 | qCWarning(LOG_VisualizationZoneWidget()) | |
573 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received."); |
|
513 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received."); | |
574 | } |
|
514 | } | |
575 | } |
|
515 | } | |
576 |
|
516 | |||
577 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( |
|
517 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( | |
578 | int index, VisualizationZoneWidget* zoneWidget) |
|
518 | int index, VisualizationZoneWidget* zoneWidget) | |
579 | { |
|
519 | { | |
580 | auto& helper = sqpApp->dragDropGuiController(); |
|
520 | auto& helper = sqpApp->dragDropGuiController(); | |
581 |
|
521 | |||
582 | auto graphWidget = qobject_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget()); |
|
522 | auto graphWidget = qobject_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget()); | |
583 | if (!graphWidget) |
|
523 | if (!graphWidget) | |
584 | { |
|
524 | { | |
585 | qCWarning(LOG_VisualizationZoneWidget()) |
|
525 | qCWarning(LOG_VisualizationZoneWidget()) | |
586 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not " |
|
526 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not " | |
587 | "found or invalid."); |
|
527 | "found or invalid."); | |
588 | Q_ASSERT(false); |
|
528 | Q_ASSERT(false); | |
589 | return; |
|
529 | return; | |
590 | } |
|
530 | } | |
591 |
|
531 | |||
592 | auto parentDragDropContainer |
|
532 | auto parentDragDropContainer | |
593 | = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget()); |
|
533 | = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget()); | |
594 | if (!parentDragDropContainer) |
|
534 | if (!parentDragDropContainer) | |
595 | { |
|
535 | { | |
596 | qCWarning(LOG_VisualizationZoneWidget()) |
|
536 | qCWarning(LOG_VisualizationZoneWidget()) | |
597 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of " |
|
537 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of " | |
598 | "the dropped graph is not found."); |
|
538 | "the dropped graph is not found."); | |
599 | Q_ASSERT(false); |
|
539 | Q_ASSERT(false); | |
600 | return; |
|
540 | return; | |
601 | } |
|
541 | } | |
602 |
|
542 | |||
603 | const auto& variables = graphWidget->variables(); |
|
543 | const auto& variables = graphWidget->variables(); | |
604 |
|
544 | |||
605 | if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.empty()) |
|
545 | if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.empty()) | |
606 | { |
|
546 | { | |
607 | // The drop didn't occur in the same zone |
|
547 | // The drop didn't occur in the same zone | |
608 |
|
548 | |||
609 | // Abort the requests for the variables (if any) |
|
549 | // Abort the requests for the variables (if any) | |
610 | // Commented, because it's not sure if it's needed or not |
|
550 | // Commented, because it's not sure if it's needed or not | |
611 | // for (const auto& var : variables) |
|
551 | // for (const auto& var : variables) | |
612 | //{ |
|
552 | //{ | |
613 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
553 | // sqpApp->variableController().onAbortProgressRequested(var); | |
614 | //} |
|
554 | //} | |
615 |
|
555 | |||
616 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); |
|
556 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); | |
617 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
557 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
618 | if (nbGraph == 1) |
|
558 | if (nbGraph == 1) | |
619 | { |
|
559 | { | |
620 | // This is the only graph in the previous zone, close the zone |
|
560 | // This is the only graph in the previous zone, close the zone | |
621 | helper.delayedCloseWidget(previousParentZoneWidget); |
|
561 | helper.delayedCloseWidget(previousParentZoneWidget); | |
622 | } |
|
562 | } | |
623 | else |
|
563 | else | |
624 | { |
|
564 | { | |
625 | // Close the graph |
|
565 | // Close the graph | |
626 | helper.delayedCloseWidget(graphWidget); |
|
566 | helper.delayedCloseWidget(graphWidget); | |
627 | } |
|
567 | } | |
628 |
|
568 | |||
629 | // Creates the new graph in the zone |
|
569 | // Creates the new graph in the zone | |
630 | auto newGraphWidget = zoneWidget->createGraph(variables, index); |
|
570 | auto newGraphWidget = zoneWidget->createGraph(variables, index); | |
631 | newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges()); |
|
571 | newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges()); | |
632 | } |
|
572 | } | |
633 | else |
|
573 | else | |
634 | { |
|
574 | { | |
635 | // The drop occurred in the same zone or the graph is empty |
|
575 | // The drop occurred in the same zone or the graph is empty | |
636 | // Simple move of the graph, no variable operation associated |
|
576 | // Simple move of the graph, no variable operation associated | |
637 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
577 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |
638 |
|
578 | |||
639 | if (variables.empty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer) |
|
579 | if (variables.empty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer) | |
640 | { |
|
580 | { | |
641 | // The graph is empty and dropped in a different zone. |
|
581 | // The graph is empty and dropped in a different zone. | |
642 | // Take the range of the first graph in the zone (if existing). |
|
582 | // Take the range of the first graph in the zone (if existing). | |
643 | auto layout = zoneWidget->ui->dragDropContainer->layout(); |
|
583 | auto layout = zoneWidget->ui->dragDropContainer->layout(); | |
644 | if (layout->count() > 0) |
|
584 | if (layout->count() > 0) | |
645 | { |
|
585 | { | |
646 | if (auto visualizationGraphWidget |
|
586 | if (auto visualizationGraphWidget | |
647 | = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget())) |
|
587 | = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget())) | |
648 | { |
|
588 | { | |
649 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); |
|
589 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); | |
650 | } |
|
590 | } | |
651 | } |
|
591 | } | |
652 | } |
|
592 | } | |
653 |
|
593 | |||
654 | zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
594 | zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget); | |
655 | } |
|
595 | } | |
656 | } |
|
596 | } | |
657 |
|
597 | |||
658 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables( |
|
598 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables( | |
659 | const std::vector<std::shared_ptr<Variable2>>& variables, int index, |
|
599 | const std::vector<std::shared_ptr<Variable2>>& variables, int index, | |
660 | VisualizationZoneWidget* zoneWidget) |
|
600 | VisualizationZoneWidget* zoneWidget) | |
661 | { |
|
601 | { | |
662 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
602 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and | |
663 | // compatible variable here |
|
603 | // compatible variable here | |
664 | if (variables.size() > 1) |
|
604 | if (variables.size() > 1) | |
665 | { |
|
605 | { | |
666 | return; |
|
606 | return; | |
667 | } |
|
607 | } | |
668 | zoneWidget->createGraph(variables, index); |
|
608 | zoneWidget->createGraph(variables, index); | |
669 | } |
|
609 | } | |
670 |
|
610 | |||
671 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropProducts( |
|
611 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropProducts( | |
672 | const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget) |
|
612 | const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget) | |
673 | { |
|
613 | { | |
674 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
614 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and | |
675 | // compatible variable here |
|
615 | // compatible variable here | |
676 | if (productsData.count() != 1) |
|
616 | if (productsData.count() != 1) | |
677 | { |
|
617 | { | |
678 | qCWarning(LOG_VisualizationZoneWidget()) |
|
618 | qCWarning(LOG_VisualizationZoneWidget()) | |
679 | << tr("VisualizationTabWidget::dropProducts, dropping multiple products, operation " |
|
619 | << tr("VisualizationTabWidget::dropProducts, dropping multiple products, operation " | |
680 | "aborted."); |
|
620 | "aborted."); | |
681 | return; |
|
621 | return; | |
682 | } |
|
622 | } | |
683 |
|
623 | |||
684 | auto context = new QObject { zoneWidget }; |
|
624 | auto context = new QObject { zoneWidget }; | |
685 | connect(&sqpApp->variableController(), &VariableController2::variableAdded, context, |
|
625 | connect(&sqpApp->variableController(), &VariableController2::variableAdded, context, | |
686 | [this, index, zoneWidget, context](auto variable) { |
|
626 | [this, index, zoneWidget, context](auto variable) { | |
687 | zoneWidget->createGraph(variable, index); |
|
627 | zoneWidget->createGraph(variable, index); | |
688 | delete context; // removes the connection |
|
628 | delete context; // removes the connection | |
689 | }, |
|
629 | }, | |
690 | Qt::QueuedConnection); |
|
630 | Qt::QueuedConnection); | |
691 |
|
631 | |||
692 | auto productPath = productsData.first().toString(); |
|
632 | auto productPath = productsData.first().toString(); | |
693 | QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable", |
|
633 | QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable", | |
694 | Qt::QueuedConnection, Q_ARG(QString, productPath)); |
|
634 | Qt::QueuedConnection, Q_ARG(QString, productPath)); | |
695 | } |
|
635 | } |
General Comments 0
You need to be logged in to leave comments.
Login now