##// END OF EJS Templates
[VisualizationGraphWidget] Restored box zoom and zones plus refac...
jeandet -
r1364:60a7242b38cd
parent child
Show More
@@ -141,7 +141,7 private:
141
141
142 class VisualizationGraphWidgetPrivate;
142 class VisualizationGraphWidgetPrivate;
143 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
143 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
144 QPoint _dragLastPos;
144
145 private slots:
145 private slots:
146 /// Slot called when right clicking on the graph (displays a menu)
146 /// Slot called when right clicking on the graph (displays a menu)
147 void onGraphMenuRequested(const QPoint &pos) noexcept;
147 void onGraphMenuRequested(const QPoint &pos) noexcept;
@@ -64,6 +64,9 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
64 m_IsCalibration{false},
64 m_IsCalibration{false},
65 m_RenderingDelegate{nullptr}
65 m_RenderingDelegate{nullptr}
66 {
66 {
67 m_plot = new QCustomPlot();
68 // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable.
69 m_plot->setPlottingHint(QCP::phFastPolylines, true);
67 }
70 }
68
71
69 void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable,
72 void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable,
@@ -80,6 +83,8 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
80 std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap;
83 std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap;
81 GraphFlags m_Flags;
84 GraphFlags m_Flags;
82 bool m_IsCalibration;
85 bool m_IsCalibration;
86 QCustomPlot* m_plot;
87 QPoint m_lastMousePos;
83 /// Delegate used to attach rendering features to the plot
88 /// Delegate used to attach rendering features to the plot
84 std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
89 std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
85
90
@@ -97,13 +102,56 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
97
102
98 bool m_VariableAutoRangeOnInit = true;
103 bool m_VariableAutoRangeOnInit = true;
99
104
100 void startDrawingRect(const QPoint &pos, QCustomPlot &plot)
105 inline void updateMousePosition(const QPoint& position)
106 {
107 m_lastMousePos = position;
108 }
109
110 inline bool isDrawingZoomRect(){return m_DrawingZoomRect!=nullptr;}
111 void updateZoomRect(const QPoint& newPos)
112 {
113 QPointF pos{m_plot->xAxis->pixelToCoord(newPos.x()), m_plot->yAxis->pixelToCoord(newPos.y())};
114 m_DrawingZoomRect->bottomRight->setCoords(pos);
115 m_plot->replot(QCustomPlot::rpQueuedReplot);
116 }
117
118 void applyZoomRect()
119 {
120 auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom);
121 auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft);
122
123 auto newAxisXRange = QCPRange{m_DrawingZoomRect->topLeft->coords().x(),
124 m_DrawingZoomRect->bottomRight->coords().x()};
125
126 auto newAxisYRange = QCPRange{m_DrawingZoomRect->topLeft->coords().y(),
127 m_DrawingZoomRect->bottomRight->coords().y()};
128
129 removeDrawingRect();
130
131 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
132 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) {
133 m_ZoomStack.push(qMakePair(axisX->range(), axisY->range()));
134 axisX->setRange(newAxisXRange);
135 axisY->setRange(newAxisYRange);
136
137 m_plot->replot(QCustomPlot::rpQueuedReplot);
138 }
139 }
140
141 inline bool isDrawingZoneRect(){return m_DrawingZone!=nullptr;}
142 void updateZoneRect(const QPoint& newPos)
101 {
143 {
102 removeDrawingRect(plot);
144 m_DrawingZone->setEnd(m_plot->xAxis->pixelToCoord(newPos.x()));
145 m_plot->replot(QCustomPlot::rpQueuedReplot);
146 }
147
148 void startDrawingRect(const QPoint &pos)
149 {
150 removeDrawingRect();
103
151
104 auto axisPos = posToAxisPos(pos, plot);
152 auto axisPos = posToAxisPos(pos);
105
153
106 m_DrawingZoomRect = new QCPItemRect{&plot};
154 m_DrawingZoomRect = new QCPItemRect{m_plot};
107 QPen p;
155 QPen p;
108 p.setWidth(2);
156 p.setWidth(2);
109 m_DrawingZoomRect->setPen(p);
157 m_DrawingZoomRect->setPen(p);
@@ -112,12 +160,12 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
112 m_DrawingZoomRect->bottomRight->setCoords(axisPos);
160 m_DrawingZoomRect->bottomRight->setCoords(axisPos);
113 }
161 }
114
162
115 void removeDrawingRect(QCustomPlot &plot)
163 void removeDrawingRect()
116 {
164 {
117 if (m_DrawingZoomRect) {
165 if (m_DrawingZoomRect) {
118 plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot
166 m_plot->removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot
119 m_DrawingZoomRect = nullptr;
167 m_DrawingZoomRect = nullptr;
120 plot.replot(QCustomPlot::rpQueuedReplot);
168 m_plot->replot(QCustomPlot::rpQueuedReplot);
121 }
169 }
122 }
170 }
123
171
@@ -125,9 +173,9 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
125 {
173 {
126 endDrawingZone(graph);
174 endDrawingZone(graph);
127
175
128 auto axisPos = posToAxisPos(pos, graph->plot());
176 auto axisPos = posToAxisPos(pos);
129
177
130 m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()};
178 m_DrawingZone = new VisualizationSelectionZoneItem{m_plot};
131 m_DrawingZone->setRange(axisPos.x(), axisPos.x());
179 m_DrawingZone->setRange(axisPos.x(), axisPos.x());
132 m_DrawingZone->setEditionEnabled(false);
180 m_DrawingZone->setEditionEnabled(false);
133 }
181 }
@@ -158,15 +206,14 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
158
206
159 void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; }
207 void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; }
160
208
161 VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos,
209 VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos) const
162 const QCustomPlot &plot) const
163 {
210 {
164 VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr;
211 VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr;
165 auto minDistanceToZone = -1;
212 auto minDistanceToZone = -1;
166 for (auto zone : m_SelectionZones) {
213 for (auto zone : m_SelectionZones) {
167 auto distanceToZone = zone->selectTest(pos, false);
214 auto distanceToZone = zone->selectTest(pos, false);
168 if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone)
215 if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone)
169 && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) {
216 && distanceToZone >= 0 && distanceToZone < m_plot->selectionTolerance()) {
170 selectionZoneItemUnderCursor = zone;
217 selectionZoneItemUnderCursor = zone;
171 }
218 }
172 }
219 }
@@ -197,10 +244,10 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
197 }
244 }
198 }
245 }
199
246
200 QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const
247 QPointF posToAxisPos(const QPoint &pos) const
201 {
248 {
202 auto axisX = plot.axisRect()->axis(QCPAxis::atBottom);
249 auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom);
203 auto axisY = plot.axisRect()->axis(QCPAxis::atLeft);
250 auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft);
204 return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())};
251 return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())};
205 }
252 }
206
253
@@ -240,15 +287,16 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
240 }
287 }
241 }
288 }
242
289
243 void moveGraph(const QPoint& origin, const QPoint& destination, QCustomPlot* plot)
290 void moveGraph(const QPoint& destination)
244 {
291 {
245 auto currentPos = destination;
292 auto currentPos = destination;
246 auto xAxis = plot->axisRect()->rangeDragAxis(Qt::Horizontal);
293 auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
247 auto yAxis = plot->axisRect()->rangeDragAxis(Qt::Vertical);
294 auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
248 xAxis->setRange(_pixDistanceToRange(origin.x(), currentPos.x(), xAxis));
295 xAxis->setRange(_pixDistanceToRange(m_lastMousePos.x(), currentPos.x(), xAxis));
249 yAxis->setRange(_pixDistanceToRange(origin.y(), currentPos.y(), yAxis));
296 yAxis->setRange(_pixDistanceToRange(m_lastMousePos.y(), currentPos.y(), yAxis));
250 setRange(xAxis->range());
297 setRange(xAxis->range());
251 plot->replot(QCustomPlot::rpQueuedReplot);
298 m_plot->replot(QCustomPlot::rpQueuedReplot);
299 m_lastMousePos = destination;
252 }
300 }
253 };
301 };
254
302
@@ -258,7 +306,7 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
258 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)}
306 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)}
259 {
307 {
260 ui->setupUi(this);
308 ui->setupUi(this);
261
309 this->layout()->addWidget(impl->m_plot);
262 // 'Close' options : widget is deleted when closed
310 // 'Close' options : widget is deleted when closed
263 setAttribute(Qt::WA_DeleteOnClose);
311 setAttribute(Qt::WA_DeleteOnClose);
264
312
@@ -271,39 +319,11 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
271 impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot());
319 impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot());
272 impl->m_VerticalCursor->setOrientation(Qt::Vertical);
320 impl->m_VerticalCursor->setOrientation(Qt::Vertical);
273
321
274 // ↓ swhitch to this ASAP, VisualizationGraphWidget should intercept all UI events
275 this->setFocusPolicy(Qt::WheelFocus);
322 this->setFocusPolicy(Qt::WheelFocus);
276 this->setMouseTracking(true);
323 this->setMouseTracking(true);
277 ui->widget->setAttribute(Qt::WA_TransparentForMouseEvents);
324 impl->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
278 // connect(ui->widget, &QCustomPlot::mousePress, this,
325 impl->m_plot->setContextMenuPolicy(Qt::CustomContextMenu);
279 // &VisualizationGraphWidget::onMousePress); connect(ui->widget, &QCustomPlot::mouseRelease,
326 impl->m_plot->setParent(this);
280 // this,
281 // &VisualizationGraphWidget::onMouseRelease);
282 // connect(ui->widget, &QCustomPlot::mouseMove, this,
283 // &VisualizationGraphWidget::onMouseMove); connect(ui->widget, &QCustomPlot::mouseWheel,
284 // this, &VisualizationGraphWidget::onMouseWheel); connect(ui->widget,
285 // &QCustomPlot::mouseDoubleClick, this,
286 // &VisualizationGraphWidget::onMouseDoubleClick);
287 // connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange
288 // &)>(
289 // &QCPAxis::rangeChanged),
290 // this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
291
292 // Activates menu when right clicking on the graph
293 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
294 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
295 &VisualizationGraphWidget::onGraphMenuRequested);
296
297 //@TODO implement this :)
298 // connect(this, &VisualizationGraphWidget::requestDataLoading,
299 // &sqpApp->variableController(),
300 // &VariableController::onRequestDataLoading);
301
302 // connect(&sqpApp->variableController(), &VariableController2::updateVarDisplaying, this,
303 // &VisualizationGraphWidget::onUpdateVarDisplaying);
304
305 // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable.
306 plot().setPlottingHint(QCP::phFastPolylines, true);
307 }
327 }
308
328
309
329
@@ -340,7 +360,7 void VisualizationGraphWidget::setFlags(GraphFlags flags)
340 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, DateTimeRange range)
360 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, DateTimeRange range)
341 {
361 {
342 // Uses delegate to create the qcpplot components according to the variable
362 // Uses delegate to create the qcpplot components according to the variable
343 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
363 auto createdPlottables = VisualizationGraphHelper::create(variable, *impl->m_plot);
344
364
345 // Sets graph properties
365 // Sets graph properties
346 impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables);
366 impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables);
@@ -374,7 +394,7 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
374
394
375 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
395 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
376 plottableIt != plottableEnd;) {
396 plottableIt != plottableEnd;) {
377 ui->widget->removePlottable(plottableIt->second);
397 impl->m_plot->removePlottable(plottableIt->second);
378 plottableIt = plottablesMap.erase(plottableIt);
398 plottableIt = plottablesMap.erase(plottableIt);
379 }
399 }
380
400
@@ -382,7 +402,7 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
382 }
402 }
383
403
384 // Updates graph
404 // Updates graph
385 ui->widget->replot(QCustomPlot::rpQueuedReplot);
405 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
386 }
406 }
387
407
388 std::vector<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const
408 std::vector<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const
@@ -403,12 +423,12 void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable)
403 return;
423 return;
404 }
424 }
405
425
406 VisualizationGraphHelper::setYAxisRange(variable, *ui->widget);
426 VisualizationGraphHelper::setYAxisRange(variable, *impl->m_plot);
407 }
427 }
408
428
409 DateTimeRange VisualizationGraphWidget::graphRange() const noexcept
429 DateTimeRange VisualizationGraphWidget::graphRange() const noexcept
410 {
430 {
411 auto graphRange = ui->widget->xAxis->range();
431 auto graphRange = impl->m_plot->xAxis->range();
412 return DateTimeRange{graphRange.lower, graphRange.upper};
432 return DateTimeRange{graphRange.lower, graphRange.upper};
413 }
433 }
414
434
@@ -418,8 +438,8 void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool ca
418 impl->m_IsCalibration = true;
438 impl->m_IsCalibration = true;
419 }
439 }
420
440
421 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
441 impl->m_plot->xAxis->setRange(range.m_TStart, range.m_TEnd);
422 ui->widget->replot(QCustomPlot::rpQueuedReplot);
442 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
423
443
424 if (calibration) {
444 if (calibration) {
425 impl->m_IsCalibration = false;
445 impl->m_IsCalibration = false;
@@ -496,22 +516,22 void VisualizationGraphWidget::undoZoom()
496 void VisualizationGraphWidget::zoom(double factor, int center, Qt::Orientation orientation)
516 void VisualizationGraphWidget::zoom(double factor, int center, Qt::Orientation orientation)
497
517
498 {
518 {
499 QCPAxis *axis = ui->widget->axisRect()->rangeZoomAxis(orientation);
519 QCPAxis *axis = impl->m_plot->axisRect()->rangeZoomAxis(orientation);
500 axis->scaleRange(factor, axis->pixelToCoord(center));
520 axis->scaleRange(factor, axis->pixelToCoord(center));
501 if (orientation == Qt::Horizontal)
521 if (orientation == Qt::Horizontal)
502 impl->setRange(axis->range());
522 impl->setRange(axis->range());
503 ui->widget->replot(QCustomPlot::rpQueuedReplot);
523 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
504 }
524 }
505
525
506 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation)
526 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation)
507 {
527 {
508 auto oldRange = ui->widget->xAxis->range();
528 auto oldRange = impl->m_plot->xAxis->range();
509 QCPAxis *axis = ui->widget->axisRect()->rangeDragAxis(orientation);
529 QCPAxis *axis = impl->m_plot->axisRect()->rangeDragAxis(orientation);
510 if (ui->widget->xAxis->scaleType() == QCPAxis::stLinear) {
530 if (impl->m_plot->xAxis->scaleType() == QCPAxis::stLinear) {
511 double rg = (axis->range().upper - axis->range().lower) * (factor / 10);
531 double rg = (axis->range().upper - axis->range().lower) * (factor / 10);
512 axis->setRange(axis->range().lower + (rg), axis->range().upper + (rg));
532 axis->setRange(axis->range().lower + (rg), axis->range().upper + (rg));
513 }
533 }
514 else if (ui->widget->xAxis->scaleType() == QCPAxis::stLogarithmic) {
534 else if (impl->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) {
515 int start = 0, stop = 0;
535 int start = 0, stop = 0;
516 double diff = 0.;
536 double diff = 0.;
517 if (factor > 0.0) {
537 if (factor > 0.0) {
@@ -524,12 +544,12 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation)
524 stop = 2 * this->width() * factor / 10;
544 stop = 2 * this->width() * factor / 10;
525 }
545 }
526 diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop);
546 diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop);
527 axis->setRange(ui->widget->axisRect()->rangeDragAxis(orientation)->range().lower * diff,
547 axis->setRange(impl->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower * diff,
528 ui->widget->axisRect()->rangeDragAxis(orientation)->range().upper * diff);
548 impl->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper * diff);
529 }
549 }
530 if (orientation == Qt::Horizontal)
550 if (orientation == Qt::Horizontal)
531 impl->setRange(axis->range());
551 impl->setRange(axis->range());
532 ui->widget->replot(QCustomPlot::rpQueuedReplot);
552 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
533 }
553 }
534
554
535 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
555 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
@@ -579,7 +599,7 QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const
579 {
599 {
580 auto mimeData = new QMimeData;
600 auto mimeData = new QMimeData;
581
601
582 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot());
602 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position);
583 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
603 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
584 && selectionZoneItemUnderCursor) {
604 && selectionZoneItemUnderCursor) {
585 mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange(
605 mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange(
@@ -599,7 +619,7 QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const
599
619
600 QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition)
620 QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition)
601 {
621 {
602 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot());
622 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition);
603 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
623 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
604 && selectionZoneItemUnderCursor) {
624 && selectionZoneItemUnderCursor) {
605
625
@@ -731,7 +751,7 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
731 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
751 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
732 {
752 {
733 setCursor(Qt::SizeVerCursor);
753 setCursor(Qt::SizeVerCursor);
734 factor = pow(ui->widget->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
754 factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
735 zoom(factor, event->pos().y(), Qt::Vertical);
755 zoom(factor, event->pos().y(), Qt::Vertical);
736 }
756 }
737 }
757 }
@@ -739,7 +759,7 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
739 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
759 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
740 {
760 {
741 setCursor(Qt::SizeHorCursor);
761 setCursor(Qt::SizeHorCursor);
742 factor = pow(ui->widget->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
762 factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
743 zoom(factor, event->pos().x(), Qt::Horizontal);
763 zoom(factor, event->pos().x(), Qt::Horizontal);
744 }
764 }
745 }
765 }
@@ -753,19 +773,17 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
753
773
754 void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent *event)
774 void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent *event)
755 {
775 {
756 if (event->buttons() == Qt::LeftButton)
776 if(impl->isDrawingZoomRect())
757 {
777 {
758 impl->moveGraph(_dragLastPos, event->pos(), ui->widget);
778 impl->updateZoomRect(event->pos());
759 _dragLastPos = event->pos();
760 }
779 }
761 else if(impl->m_DrawingZoomRect)
780 else if (impl->isDrawingZoneRect())
762 {
781 {
763 QPointF pos{ui->widget->xAxis->pixelToCoord(event->pos().x()), ui->widget->yAxis->pixelToCoord(event->pos().y())};
782 impl->updateZoneRect(event->pos());
764 impl->m_DrawingZoomRect->bottomRight->setCoords(pos);
765 }
783 }
766 else if (impl->m_DrawingZone)
784 else if (event->buttons() == Qt::LeftButton)
767 {
785 {
768 impl->m_DrawingZone->setEnd(ui->widget->xAxis->pixelToCoord(event->pos().x()));
786 impl->moveGraph(event->pos());
769 }
787 }
770 else
788 else
771 {
789 {
@@ -777,7 +795,18 void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent *event)
777
795
778 void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event)
796 void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event)
779 {
797 {
798 if(impl->isDrawingZoomRect())
799 {
800 impl->applyZoomRect();
801 }
802 else if(impl->isDrawingZoneRect())
803 {
804 impl->endDrawingZone(this);
805 }
806 else
807 {
780 setCursor(Qt::ArrowCursor);
808 setCursor(Qt::ArrowCursor);
809 }
781 QWidget::mouseReleaseEvent(event);
810 QWidget::mouseReleaseEvent(event);
782 }
811 }
783
812
@@ -786,9 +815,27 void VisualizationGraphWidget::mousePressEvent(QMouseEvent *event)
786 if (event->button() == Qt::LeftButton) {
815 if (event->button() == Qt::LeftButton) {
787 if (event->modifiers() == Qt::ControlModifier) {
816 if (event->modifiers() == Qt::ControlModifier) {
788 }
817 }
789 else {
818 else if (event->modifiers() == Qt::AltModifier) {
819
820 }
821 else
822 {
823 switch (sqpApp->plotsInteractionMode())
824 {
825 case SqpApplication::PlotsInteractionMode::DragAndDrop :
826 break;
827 case SqpApplication::PlotsInteractionMode::SelectionZones :
828 if (!impl->selectionZoneAt(event->pos())) {
829 impl->startDrawingZone(event->pos(), this);
830 }
831 break;
832 case SqpApplication::PlotsInteractionMode::ZoomBox :
833 impl->startDrawingRect(event->pos());
834 break;
835 default:
790 setCursor(Qt::ClosedHandCursor);
836 setCursor(Qt::ClosedHandCursor);
791 this->_dragLastPos = event->pos();
837 impl->updateMousePosition(event->pos());
838 }
792 }
839 }
793 }
840 }
794 else if (event->button()==Qt::RightButton)
841 else if (event->button()==Qt::RightButton)
@@ -828,8 +875,8 void VisualizationGraphWidget::keyPressEvent(QKeyEvent *event)
828 case Qt::Key_Shift:
875 case Qt::Key_Shift:
829 break;
876 break;
830 case Qt::Key_M:
877 case Qt::Key_M:
831 ui->widget->rescaleAxes();
878 impl->m_plot->rescaleAxes();
832 ui->widget->replot(QCustomPlot::rpQueuedReplot);
879 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
833 break;
880 break;
834 case Qt::Key_Left:
881 case Qt::Key_Left:
835 if (event->modifiers() != Qt::ControlModifier) {
882 if (event->modifiers() != Qt::ControlModifier) {
@@ -871,7 +918,7 void VisualizationGraphWidget::keyPressEvent(QKeyEvent *event)
871
918
872 QCustomPlot &VisualizationGraphWidget::plot() const noexcept
919 QCustomPlot &VisualizationGraphWidget::plot() const noexcept
873 {
920 {
874 return *ui->widget;
921 return *impl->m_plot;
875 }
922 }
876
923
877 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
924 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
@@ -896,7 +943,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
896 }
943 }
897
944
898 // Selection Zone Actions
945 // Selection Zone Actions
899 auto selectionZoneItem = impl->selectionZoneAt(pos, plot());
946 auto selectionZoneItem = impl->selectionZoneAt(pos);
900 if (selectionZoneItem) {
947 if (selectionZoneItem) {
901 auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems();
948 auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems();
902 selectedItems.removeAll(selectionZoneItem);
949 selectedItems.removeAll(selectionZoneItem);
@@ -966,39 +1013,6 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
966 }
1013 }
967 }
1014 }
968
1015
969 //void VisualizationGraphWidget::onRangeChanged(const QCPRange &newRange, const QCPRange &oldRange)
970 //{
971 // auto graphRange = DateTimeRange{newRange.lower, newRange.upper};
972 // auto oldGraphRange = DateTimeRange{oldRange.lower, oldRange.upper};
973
974 // if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) {
975 // for (auto it = impl->m_VariableToPlotMultiMap.begin(),
976 // end = impl->m_VariableToPlotMultiMap.end();
977 // it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
978 // sqpApp->variableController().asyncChangeRange(it->first, graphRange);
979 // }
980 // }
981
982 // // if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration)
983 // // {
984 // // emit synchronize(graphRange, oldGraphRange);
985 // // }
986
987 // // auto pos = mapFromGlobal(QCursor::pos());
988 // // auto axisPos = impl->posToAxisPos(pos, plot());
989 // // if (auto parentZone = parentZoneWidget()) {
990 // // if (impl->pointIsInAxisRect(axisPos, plot())) {
991 // // parentZone->notifyMouseMoveInGraph(pos, axisPos, this);
992 // // }
993 // // else {
994 // // parentZone->notifyMouseLeaveGraph(this);
995 // // }
996 // // }
997
998 // // Quits calibration
999 // // impl->m_IsCalibration = false;
1000 //}
1001
1002 void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept
1016 void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept
1003 {
1017 {
1004 impl->m_RenderingDelegate->onMouseDoubleClick(event);
1018 impl->m_RenderingDelegate->onMouseDoubleClick(event);
@@ -1009,7 +1023,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1009 // Handles plot rendering when mouse is moving
1023 // Handles plot rendering when mouse is moving
1010 impl->m_RenderingDelegate->updateTooltip(event);
1024 impl->m_RenderingDelegate->updateTooltip(event);
1011
1025
1012 auto axisPos = impl->posToAxisPos(event->pos(), plot());
1026 auto axisPos = impl->posToAxisPos(event->pos());
1013
1027
1014 // Zoom box and zone drawing
1028 // Zoom box and zone drawing
1015 if (impl->m_DrawingZoomRect) {
1029 if (impl->m_DrawingZoomRect) {
@@ -1030,7 +1044,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1030 }
1044 }
1031
1045
1032 // Search for the selection zone under the mouse
1046 // Search for the selection zone under the mouse
1033 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot());
1047 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1034 if (selectionZoneItemUnderCursor && !impl->m_DrawingZone
1048 if (selectionZoneItemUnderCursor && !impl->m_DrawingZone
1035 && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) {
1049 && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) {
1036
1050
@@ -1065,7 +1079,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1065 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
1079 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
1066 {
1080 {
1067 // Processes event only if the wheel occurs on axis rect
1081 // Processes event only if the wheel occurs on axis rect
1068 if (!dynamic_cast<QCPAxisRect *>(ui->widget->layoutElementAt(event->posF()))) {
1082 if (!dynamic_cast<QCPAxisRect *>(impl->m_plot->layoutElementAt(event->posF()))) {
1069 return;
1083 return;
1070 }
1084 }
1071
1085
@@ -1081,7 +1095,7 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
1081 zoomOrientations.setFlag(Qt::Horizontal, isZoomX);
1095 zoomOrientations.setFlag(Qt::Horizontal, isZoomX);
1082 zoomOrientations.setFlag(Qt::Vertical, isZoomY);
1096 zoomOrientations.setFlag(Qt::Vertical, isZoomY);
1083
1097
1084 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
1098 impl->m_plot->axisRect()->setRangeZoom(zoomOrientations);
1085
1099
1086 if (!isZoomX && !isZoomY) {
1100 if (!isZoomX && !isZoomY) {
1087 auto axis = plot().axisRect()->axis(QCPAxis::atBottom);
1101 auto axis = plot().axisRect()->axis(QCPAxis::atBottom);
@@ -1108,11 +1122,11 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
1108 if (!isDragDropClick && isLeftClick) {
1122 if (!isDragDropClick && isLeftClick) {
1109 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) {
1123 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) {
1110 // Starts a zoom box
1124 // Starts a zoom box
1111 impl->startDrawingRect(event->pos(), plot());
1125 impl->startDrawingRect(event->pos());
1112 }
1126 }
1113 else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) {
1127 else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) {
1114 // Starts a new selection zone
1128 // Starts a new selection zone
1115 auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot());
1129 auto zoneAtPos = impl->selectionZoneAt(event->pos());
1116 if (!zoneAtPos) {
1130 if (!zoneAtPos) {
1117 impl->startDrawingZone(event->pos(), this);
1131 impl->startDrawingZone(event->pos(), this);
1118 }
1132 }
@@ -1126,7 +1140,7 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
1126 // Selection / Deselection
1140 // Selection / Deselection
1127 if (isSelectionZoneMode) {
1141 if (isSelectionZoneMode) {
1128 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1142 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1129 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot());
1143 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1130
1144
1131
1145
1132 if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected()
1146 if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected()
@@ -1165,7 +1179,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1165 auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(),
1179 auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(),
1166 impl->m_DrawingZoomRect->bottomRight->coords().y()};
1180 impl->m_DrawingZoomRect->bottomRight->coords().y()};
1167
1181
1168 impl->removeDrawingRect(plot());
1182 impl->removeDrawingRect();
1169
1183
1170 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
1184 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
1171 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) {
1185 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) {
@@ -1184,7 +1198,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1184 = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones;
1198 = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones;
1185 if (isSelectionZoneMode) {
1199 if (isSelectionZoneMode) {
1186 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1200 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1187 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot());
1201 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1188 if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton
1202 if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton
1189 && !impl->m_HasMovedMouse) {
1203 && !impl->m_HasMovedMouse) {
1190
1204
@@ -1238,7 +1252,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1238
1252
1239 void VisualizationGraphWidget::onDataCacheVariableUpdated()
1253 void VisualizationGraphWidget::onDataCacheVariableUpdated()
1240 {
1254 {
1241 auto graphRange = ui->widget->xAxis->range();
1255 auto graphRange = impl->m_plot->xAxis->range();
1242 auto dateTime = DateTimeRange{graphRange.lower, graphRange.upper};
1256 auto dateTime = DateTimeRange{graphRange.lower, graphRange.upper};
1243
1257
1244 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
1258 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
@@ -26,26 +26,8
26 <property name="bottomMargin">
26 <property name="bottomMargin">
27 <number>0</number>
27 <number>0</number>
28 </property>
28 </property>
29 <item>
30 <widget class="QCustomPlot" name="widget" native="true">
31 <property name="sizePolicy">
32 <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
33 <horstretch>0</horstretch>
34 <verstretch>0</verstretch>
35 </sizepolicy>
36 </property>
37 </widget>
38 </item>
39 </layout>
29 </layout>
40 </widget>
30 </widget>
41 <customwidgets>
42 <customwidget>
43 <class>QCustomPlot</class>
44 <extends>QWidget</extends>
45 <header>Visualization/qcustomplot.h</header>
46 <container>1</container>
47 </customwidget>
48 </customwidgets>
49 <resources/>
31 <resources/>
50 <connections/>
32 <connections/>
51 </ui>
33 </ui>
General Comments 0
You need to be logged in to leave comments. Login now