@@ -1,82 +1,82 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include <QLoggingCategory> |
|
7 | 7 | #include <QWidget> |
|
8 | 8 | |
|
9 | 9 | #include <memory> |
|
10 | 10 | |
|
11 | 11 | #include <Common/spimpl.h> |
|
12 | 12 | |
|
13 | 13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
14 | 14 | |
|
15 | 15 | class QCPRange; |
|
16 | 16 | class SqpDateTime; |
|
17 | 17 | class Variable; |
|
18 | 18 | |
|
19 | 19 | /** |
|
20 | 20 | * Possible types of zoom operation |
|
21 | 21 | */ |
|
22 | 22 | enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; |
|
23 | 23 | |
|
24 | 24 | namespace Ui { |
|
25 | 25 | class VisualizationGraphWidget; |
|
26 | 26 | } // namespace Ui |
|
27 | 27 | |
|
28 | 28 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
29 | 29 | Q_OBJECT |
|
30 | 30 | |
|
31 | 31 | public: |
|
32 | 32 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
33 | 33 | virtual ~VisualizationGraphWidget(); |
|
34 | 34 | |
|
35 | 35 | void enableSynchronize(bool enable); |
|
36 | 36 | |
|
37 | 37 | void addVariable(std::shared_ptr<Variable> variable); |
|
38 | 38 | void addVariableUsingGraph(std::shared_ptr<Variable> variable); |
|
39 | 39 | /// Removes a variable from the graph |
|
40 | 40 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
41 | 41 | |
|
42 | 42 | void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range); |
|
43 | 43 | SqpDateTime graphRange() const noexcept; |
|
44 | 44 | void setGraphRange(const SqpDateTime &range); |
|
45 | 45 | |
|
46 | 46 | // IVisualizationWidget interface |
|
47 | 47 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
48 | 48 | bool canDrop(const Variable &variable) const override; |
|
49 | 49 | bool contains(const Variable &variable) const override; |
|
50 | 50 | QString name() const override; |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | signals: |
|
54 | 54 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
55 | 55 | void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime, |
|
56 | 56 | VisualizationGraphWidgetZoomType zoomType); |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | private: |
|
60 | 60 | Ui::VisualizationGraphWidget *ui; |
|
61 | 61 | |
|
62 | 62 | class VisualizationGraphWidgetPrivate; |
|
63 | 63 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
64 | 64 | |
|
65 | 65 | private slots: |
|
66 | 66 | /// Slot called when right clicking on the graph (displays a menu) |
|
67 | 67 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
68 | 68 | |
|
69 | 69 | /// Rescale the X axe to range parameter |
|
70 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
|
70 | void processRangeChange(); | |
|
71 | 71 | |
|
72 | 72 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
73 | 73 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
74 | 74 | /// Slot called when a mouse press was made, to activate the calibration of a graph |
|
75 | 75 | void onMousePress(QMouseEvent *event) noexcept; |
|
76 | 76 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph |
|
77 | 77 | void onMouseRelease(QMouseEvent *event) noexcept; |
|
78 | 78 | |
|
79 | 79 | void onDataCacheVariableUpdated(); |
|
80 | 80 | }; |
|
81 | 81 | |
|
82 | 82 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,401 +1,420 | |||
|
1 | 1 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | 4 | #include "ui_VisualizationGraphWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/ArrayData.h> |
|
7 | 7 | #include <Data/IDataSeries.h> |
|
8 | 8 | #include <SqpApplication.h> |
|
9 | 9 | #include <Variable/Variable.h> |
|
10 | 10 | #include <Variable/VariableController.h> |
|
11 | 11 | |
|
12 | 12 | #include <unordered_map> |
|
13 | 13 | |
|
14 | 14 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
15 | 15 | |
|
16 | 16 | namespace { |
|
17 | 17 | |
|
18 | /// Timeout from which the mouse wheel is considered completed (in ms) | |
|
19 | const auto MOUSE_WHEEL_TIMEOUT = 250; | |
|
20 | ||
|
18 | 21 | /// Key pressed to enable zoom on horizontal axis |
|
19 | 22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
20 | 23 | |
|
21 | 24 | /// Key pressed to enable zoom on vertical axis |
|
22 | 25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
23 | 26 | |
|
24 | 27 | } // namespace |
|
25 | 28 | |
|
26 | 29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
27 | 30 | |
|
28 |
explicit VisualizationGraphWidgetPrivate() |
|
|
31 | explicit VisualizationGraphWidgetPrivate() | |
|
32 | : m_DoSynchronize{true}, m_IsCalibration{false}, m_RefRange{}, m_MouseWheelTimer{} | |
|
33 | { | |
|
34 | m_MouseWheelTimer.setSingleShot(true); | |
|
35 | } | |
|
29 | 36 | |
|
30 | 37 | |
|
31 | 38 | // Return the operation when range changed |
|
32 | 39 | VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2); |
|
33 | 40 | |
|
34 | 41 | // 1 variable -> n qcpplot |
|
35 | 42 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; |
|
36 | 43 | |
|
37 | 44 | bool m_DoSynchronize; |
|
38 | 45 | bool m_IsCalibration; |
|
46 | QCPRange m_RefRange; | |
|
47 | QTimer m_MouseWheelTimer; | |
|
39 | 48 | }; |
|
40 | 49 | |
|
41 | 50 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
42 | 51 | : QWidget{parent}, |
|
43 | 52 | ui{new Ui::VisualizationGraphWidget}, |
|
44 | 53 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
45 | 54 | { |
|
46 | 55 | ui->setupUi(this); |
|
47 | 56 | |
|
48 | 57 | ui->graphNameLabel->setText(name); |
|
49 | 58 | |
|
50 | 59 | // 'Close' options : widget is deleted when closed |
|
51 | 60 | setAttribute(Qt::WA_DeleteOnClose); |
|
52 | 61 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
53 | 62 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
54 | 63 | |
|
55 | 64 | // Set qcpplot properties : |
|
56 | 65 | // - Drag (on x-axis) and zoom are enabled |
|
57 | 66 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
58 | 67 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
59 | 68 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
60 | 69 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
61 | 70 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
62 | 71 | &VisualizationGraphWidget::onMouseRelease); |
|
63 | 72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
64 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
|
65 | &QCPAxis::rangeChanged), | |
|
66 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
|
73 | ||
|
74 | // Connects mouse wheel timer | |
|
75 | connect(&impl->m_MouseWheelTimer, &QTimer::timeout, this, | |
|
76 | &VisualizationGraphWidget::processRangeChange); | |
|
67 | 77 | |
|
68 | 78 | // Activates menu when right clicking on the graph |
|
69 | 79 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
70 | 80 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
71 | 81 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
72 | 82 | |
|
73 | 83 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
74 | 84 | &VariableController::onRequestDataLoading); |
|
75 | 85 | } |
|
76 | 86 | |
|
77 | 87 | |
|
78 | 88 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
79 | 89 | { |
|
80 | 90 | delete ui; |
|
81 | 91 | } |
|
82 | 92 | |
|
83 | 93 | void VisualizationGraphWidget::enableSynchronize(bool enable) |
|
84 | 94 | { |
|
85 | 95 | impl->m_DoSynchronize = enable; |
|
86 | 96 | } |
|
87 | 97 | |
|
88 | 98 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
89 | 99 | { |
|
90 | 100 | // Uses delegate to create the qcpplot components according to the variable |
|
91 | 101 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
92 | 102 | |
|
93 | 103 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
94 | 104 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
95 | 105 | } |
|
96 | 106 | |
|
97 | 107 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
98 | 108 | } |
|
99 | 109 | void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable) |
|
100 | 110 | { |
|
101 | 111 | |
|
102 | 112 | // when adding a variable, we need to set its time range to the current graph range |
|
103 | 113 | auto grapheRange = ui->widget->xAxis->range(); |
|
104 | 114 | auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper}; |
|
105 | 115 | variable->setDateTime(dateTime); |
|
106 | 116 | |
|
107 | 117 | auto variableDateTimeWithTolerance = dateTime; |
|
108 | 118 | |
|
109 | 119 | // add 20% tolerance for each side |
|
110 | 120 | auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
111 | 121 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
112 | 122 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
113 | 123 | |
|
114 | 124 | // Uses delegate to create the qcpplot components according to the variable |
|
115 | 125 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
116 | 126 | |
|
117 | 127 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
118 | 128 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
119 | 129 | } |
|
120 | 130 | |
|
121 | 131 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
122 | 132 | |
|
123 | 133 | // CHangement detected, we need to ask controller to request data loading |
|
124 | 134 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
125 | 135 | } |
|
126 | 136 | |
|
127 | 137 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
128 | 138 | { |
|
129 | 139 | // Each component associated to the variable : |
|
130 | 140 | // - is removed from qcpplot (which deletes it) |
|
131 | 141 | // - is no longer referenced in the map |
|
132 | 142 | auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
133 | 143 | for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
134 | 144 | ui->widget->removePlottable(it->second); |
|
135 | 145 | it = impl->m_VariableToPlotMultiMap.erase(it); |
|
136 | 146 | } |
|
137 | 147 | |
|
138 | 148 | // Updates graph |
|
139 | 149 | ui->widget->replot(); |
|
140 | 150 | } |
|
141 | 151 | |
|
142 | 152 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, |
|
143 | 153 | const SqpDateTime &range) |
|
144 | 154 | { |
|
145 | 155 | // Note: in case of different axes that depends on variable, we could start with a code like |
|
146 | 156 | // that: |
|
147 | 157 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
148 | 158 | // for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
149 | 159 | // } |
|
150 | 160 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
151 | 161 | ui->widget->replot(); |
|
152 | 162 | } |
|
153 | 163 | |
|
154 | 164 | SqpDateTime VisualizationGraphWidget::graphRange() const noexcept |
|
155 | 165 | { |
|
156 | 166 | auto grapheRange = ui->widget->xAxis->range(); |
|
157 | 167 | return SqpDateTime{grapheRange.lower, grapheRange.upper}; |
|
158 | 168 | } |
|
159 | 169 | |
|
160 | 170 | void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range) |
|
161 | 171 | { |
|
162 | 172 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
163 | 173 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
164 | 174 | ui->widget->replot(); |
|
165 | 175 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
166 | 176 | } |
|
167 | 177 | |
|
168 | 178 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
169 | 179 | { |
|
170 | 180 | if (visitor) { |
|
171 | 181 | visitor->visit(this); |
|
172 | 182 | } |
|
173 | 183 | else { |
|
174 | 184 | qCCritical(LOG_VisualizationGraphWidget()) |
|
175 | 185 | << tr("Can't visit widget : the visitor is null"); |
|
176 | 186 | } |
|
177 | 187 | } |
|
178 | 188 | |
|
179 | 189 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
180 | 190 | { |
|
181 | 191 | /// @todo : for the moment, a graph can always accomodate a variable |
|
182 | 192 | Q_UNUSED(variable); |
|
183 | 193 | return true; |
|
184 | 194 | } |
|
185 | 195 | |
|
186 | 196 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
187 | 197 | { |
|
188 | 198 | // Finds the variable among the keys of the map |
|
189 | 199 | auto variablePtr = &variable; |
|
190 | 200 | auto findVariable |
|
191 | 201 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
192 | 202 | |
|
193 | 203 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
194 | 204 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
195 | 205 | return it != end; |
|
196 | 206 | } |
|
197 | 207 | |
|
198 | 208 | QString VisualizationGraphWidget::name() const |
|
199 | 209 | { |
|
200 | 210 | return ui->graphNameLabel->text(); |
|
201 | 211 | } |
|
202 | 212 | |
|
203 | 213 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
204 | 214 | { |
|
205 | 215 | QMenu graphMenu{}; |
|
206 | 216 | |
|
207 | 217 | // Iterates on variables (unique keys) |
|
208 | 218 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
209 | 219 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
210 | 220 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
211 | 221 | // 'Remove variable' action |
|
212 | 222 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
213 | 223 | [ this, var = it->first ]() { removeVariable(var); }); |
|
214 | 224 | } |
|
215 | 225 | |
|
216 | 226 | if (!graphMenu.isEmpty()) { |
|
217 | 227 | graphMenu.exec(mapToGlobal(pos)); |
|
218 | 228 | } |
|
219 | 229 | } |
|
220 | 230 | |
|
221 |
void VisualizationGraphWidget:: |
|
|
231 | void VisualizationGraphWidget::processRangeChange() | |
|
222 | 232 | { |
|
223 |
qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget:: |
|
|
233 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::processRangeChange") | |
|
224 | 234 | << QThread::currentThread()->objectName(); |
|
225 | 235 | |
|
226 | auto dateTimeRange = SqpDateTime{t1.lower, t1.upper}; | |
|
236 | auto oldRange = impl->m_RefRange; | |
|
237 | auto newRange = ui->widget->xAxis->range(); | |
|
227 | 238 | |
|
228 | auto zoomType = impl->getZoomType(t1, t2); | |
|
239 | auto dateTimeRange = SqpDateTime{newRange.lower, newRange.upper}; | |
|
240 | ||
|
241 | auto zoomType = impl->getZoomType(newRange, impl->m_RefRange); | |
|
229 | 242 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
230 | 243 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
231 | 244 | |
|
232 | 245 | auto variable = it->first; |
|
233 | 246 | auto currentDateTime = dateTimeRange; |
|
234 | 247 | |
|
235 | 248 | auto toleranceFactor = 0.2; |
|
236 | 249 | auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); |
|
237 | 250 | auto variableDateTimeWithTolerance = currentDateTime; |
|
238 | 251 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
239 | 252 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
240 | 253 | |
|
241 | 254 | qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime; |
|
242 | 255 | qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance; |
|
243 | 256 | qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime(); |
|
244 | 257 | // If new range with tol is upper than variable datetime parameters. we need to request new |
|
245 | 258 | // data |
|
246 | 259 | if (!variable->contains(variableDateTimeWithTolerance)) { |
|
247 | 260 | |
|
248 | 261 | auto variableDateTimeWithTolerance = currentDateTime; |
|
249 | 262 | if (!variable->isInside(currentDateTime)) { |
|
250 | 263 | auto variableDateTime = variable->dateTime(); |
|
251 | 264 | if (variable->contains(variableDateTimeWithTolerance)) { |
|
252 | 265 | qCDebug(LOG_VisualizationGraphWidget()) |
|
253 | 266 | << tr("TORM: Detection zoom in that need request:"); |
|
254 | 267 | // add 10% tolerance for each side |
|
255 | 268 | tolerance |
|
256 | 269 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); |
|
257 | 270 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
258 | 271 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
259 | 272 | } |
|
260 | 273 | else if (variableDateTime.m_TStart < currentDateTime.m_TStart) { |
|
261 | 274 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:"); |
|
262 | 275 | |
|
263 | 276 | auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd; |
|
264 | 277 | currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; |
|
265 | 278 | // Tolerance have to be added to the right |
|
266 | 279 | // add tolerance for right (end) side |
|
267 | 280 | tolerance |
|
268 | 281 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); |
|
269 | 282 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
270 | 283 | } |
|
271 | 284 | else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) { |
|
272 | 285 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: "); |
|
273 | 286 | auto diffStartToKeepDelta |
|
274 | 287 | = variableDateTime.m_TStart - currentDateTime.m_TStart; |
|
275 | 288 | currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; |
|
276 | 289 | // Tolerance have to be added to the left |
|
277 | 290 | // add tolerance for left (start) side |
|
278 | 291 | tolerance |
|
279 | 292 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); |
|
280 | 293 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
281 | 294 | } |
|
282 | 295 | else { |
|
283 | 296 | qCCritical(LOG_VisualizationGraphWidget()) |
|
284 | 297 | << tr("Detection anormal zoom detection: "); |
|
285 | 298 | } |
|
286 | 299 | } |
|
287 | 300 | else { |
|
288 | 301 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: "); |
|
289 | 302 | // add 10% tolerance for each side |
|
290 | 303 | tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); |
|
291 | 304 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
292 | 305 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
293 | 306 | zoomType = VisualizationGraphWidgetZoomType::ZoomOut; |
|
294 | 307 | } |
|
295 | 308 | if (!variable->contains(dateTimeRange)) { |
|
296 | 309 | qCDebug(LOG_VisualizationGraphWidget()) |
|
297 | 310 | << "TORM: Modif on variable datetime detected" << currentDateTime; |
|
298 | 311 | variable->setDateTime(currentDateTime); |
|
299 | 312 | } |
|
300 | 313 | |
|
301 | 314 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: "); |
|
302 | 315 | // CHangement detected, we need to ask controller to request data loading |
|
303 | 316 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
304 | 317 | } |
|
305 | 318 | else { |
|
306 | 319 | qCInfo(LOG_VisualizationGraphWidget()) |
|
307 | 320 | << tr("TORM: Detection zoom in that doesn't need request: "); |
|
308 | 321 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; |
|
309 | 322 | } |
|
310 | 323 | } |
|
311 | 324 | |
|
312 | 325 | if (impl->m_DoSynchronize && !impl->m_IsCalibration) { |
|
313 |
auto oldDateTime = SqpDateTime{ |
|
|
326 | auto oldDateTime = SqpDateTime{oldRange.lower, oldRange.upper}; | |
|
314 | 327 | qCDebug(LOG_VisualizationGraphWidget()) |
|
315 | 328 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
316 | 329 | << QThread::currentThread()->objectName(); |
|
317 | 330 | emit synchronize(dateTimeRange, oldDateTime, zoomType); |
|
318 | 331 | } |
|
332 | ||
|
333 | impl->m_RefRange = newRange; | |
|
319 | 334 | } |
|
320 | 335 | |
|
321 | 336 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
322 | 337 | { |
|
338 | impl->m_MouseWheelTimer.start(MOUSE_WHEEL_TIMEOUT); | |
|
339 | ||
|
323 | 340 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
324 | 341 | |
|
325 | 342 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
326 | 343 | // has |
|
327 | 344 | // been pressed |
|
328 | 345 | auto enableOrientation |
|
329 | 346 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
330 | 347 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
331 | 348 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
332 | 349 | }; |
|
333 | 350 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
334 | 351 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
335 | 352 | |
|
336 | 353 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
337 | 354 | } |
|
338 | 355 | |
|
339 | 356 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
340 | 357 | { |
|
358 | impl->m_RefRange = ui->widget->xAxis->range(); | |
|
341 | 359 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
342 | 360 | } |
|
343 | 361 | |
|
344 | 362 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
345 | 363 | { |
|
346 | 364 | impl->m_IsCalibration = false; |
|
365 | processRangeChange(); | |
|
347 | 366 | } |
|
348 | 367 | |
|
349 | 368 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
350 | 369 | { |
|
351 | 370 | // NOTE: |
|
352 | 371 | // We don't want to call the method for each component of a variable unitarily, but for |
|
353 | 372 | // all |
|
354 | 373 | // its components at once (eg its three components in the case of a vector). |
|
355 | 374 | |
|
356 | 375 | // The unordered_multimap does not do this easily, so the question is whether to: |
|
357 | 376 | // - use an ordered_multimap and the algos of std to group the values by key |
|
358 | 377 | // - use a map (unique keys) and store as values directly the list of components |
|
359 | 378 | |
|
360 | 379 | auto grapheRange = ui->widget->xAxis->range(); |
|
361 | 380 | auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper}; |
|
362 | 381 | |
|
363 | 382 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
364 | 383 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
365 | 384 | auto variable = it->first; |
|
366 | 385 | qCDebug(LOG_VisualizationGraphWidget()) |
|
367 | 386 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" |
|
368 | 387 | << variable->dateTime(); |
|
369 | 388 | qCDebug(LOG_VisualizationGraphWidget()) |
|
370 | 389 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
371 | 390 | if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) { |
|
372 | 391 | |
|
373 | 392 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
374 | 393 | variable->dataSeries(), variable->dateTime()); |
|
375 | 394 | } |
|
376 | 395 | } |
|
377 | 396 | } |
|
378 | 397 | |
|
379 | 398 | VisualizationGraphWidgetZoomType |
|
380 | 399 | VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1, |
|
381 | 400 | const QCPRange &t2) |
|
382 | 401 | { |
|
383 | 402 | // t1.lower <= t2.lower && t2.upper <= t1.upper |
|
384 | 403 | auto zoomType = VisualizationGraphWidgetZoomType::Unknown; |
|
385 | 404 | if (t1.lower <= t2.lower && t2.upper <= t1.upper) { |
|
386 | 405 | zoomType = VisualizationGraphWidgetZoomType::ZoomOut; |
|
387 | 406 | } |
|
388 | 407 | else if (t1.lower > t2.lower && t1.upper > t2.upper) { |
|
389 | 408 | zoomType = VisualizationGraphWidgetZoomType::PanRight; |
|
390 | 409 | } |
|
391 | 410 | else if (t1.lower < t2.lower && t1.upper < t2.upper) { |
|
392 | 411 | zoomType = VisualizationGraphWidgetZoomType::PanLeft; |
|
393 | 412 | } |
|
394 | 413 | else if (t1.lower > t2.lower && t2.upper > t1.upper) { |
|
395 | 414 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; |
|
396 | 415 | } |
|
397 | 416 | else { |
|
398 | 417 | qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected"; |
|
399 | 418 | } |
|
400 | 419 | return zoomType; |
|
401 | 420 | } |
General Comments 0
You need to be logged in to leave comments.
Login now