##// 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 142 class VisualizationGraphWidgetPrivate;
143 143 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
144 QPoint _dragLastPos;
144
145 145 private slots:
146 146 /// Slot called when right clicking on the graph (displays a menu)
147 147 void onGraphMenuRequested(const QPoint &pos) noexcept;
@@ -64,6 +64,9 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
64 64 m_IsCalibration{false},
65 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 72 void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable,
@@ -80,10 +83,12 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
80 83 std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap;
81 84 GraphFlags m_Flags;
82 85 bool m_IsCalibration;
86 QCustomPlot* m_plot;
87 QPoint m_lastMousePos;
83 88 /// Delegate used to attach rendering features to the plot
84 89 std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
85 90
86 QCPItemRect *m_DrawingZoomRect = nullptr;
91 QCPItemRect* m_DrawingZoomRect = nullptr;
87 92 QStack<QPair<QCPRange, QCPRange> > m_ZoomStack;
88 93
89 94 std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr;
@@ -97,13 +102,56 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
97 102
98 103 bool m_VariableAutoRangeOnInit = true;
99 104
100 void startDrawingRect(const QPoint &pos, QCustomPlot &plot)
105 inline void updateMousePosition(const QPoint& position)
101 106 {
102 removeDrawingRect(plot);
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)
143 {
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 155 QPen p;
108 156 p.setWidth(2);
109 157 m_DrawingZoomRect->setPen(p);
@@ -112,12 +160,12 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
112 160 m_DrawingZoomRect->bottomRight->setCoords(axisPos);
113 161 }
114 162
115 void removeDrawingRect(QCustomPlot &plot)
163 void removeDrawingRect()
116 164 {
117 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 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 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 179 m_DrawingZone->setRange(axisPos.x(), axisPos.x());
132 180 m_DrawingZone->setEditionEnabled(false);
133 181 }
@@ -158,15 +206,14 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
158 206
159 207 void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; }
160 208
161 VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos,
162 const QCustomPlot &plot) const
209 VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos) const
163 210 {
164 211 VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr;
165 212 auto minDistanceToZone = -1;
166 213 for (auto zone : m_SelectionZones) {
167 214 auto distanceToZone = zone->selectTest(pos, false);
168 215 if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone)
169 && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) {
216 && distanceToZone >= 0 && distanceToZone < m_plot->selectionTolerance()) {
170 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);
203 auto axisY = plot.axisRect()->axis(QCPAxis::atLeft);
249 auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom);
250 auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft);
204 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 292 auto currentPos = destination;
246 auto xAxis = plot->axisRect()->rangeDragAxis(Qt::Horizontal);
247 auto yAxis = plot->axisRect()->rangeDragAxis(Qt::Vertical);
248 xAxis->setRange(_pixDistanceToRange(origin.x(), currentPos.x(), xAxis));
249 yAxis->setRange(_pixDistanceToRange(origin.y(), currentPos.y(), yAxis));
293 auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
294 auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
295 xAxis->setRange(_pixDistanceToRange(m_lastMousePos.x(), currentPos.x(), xAxis));
296 yAxis->setRange(_pixDistanceToRange(m_lastMousePos.y(), currentPos.y(), yAxis));
250 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 306 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)}
259 307 {
260 308 ui->setupUi(this);
261
309 this->layout()->addWidget(impl->m_plot);
262 310 // 'Close' options : widget is deleted when closed
263 311 setAttribute(Qt::WA_DeleteOnClose);
264 312
@@ -271,39 +319,11 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
271 319 impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot());
272 320 impl->m_VerticalCursor->setOrientation(Qt::Vertical);
273 321
274 // ↓ swhitch to this ASAP, VisualizationGraphWidget should intercept all UI events
275 322 this->setFocusPolicy(Qt::WheelFocus);
276 323 this->setMouseTracking(true);
277 ui->widget->setAttribute(Qt::WA_TransparentForMouseEvents);
278 // connect(ui->widget, &QCustomPlot::mousePress, this,
279 // &VisualizationGraphWidget::onMousePress); connect(ui->widget, &QCustomPlot::mouseRelease,
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);
324 impl->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
325 impl->m_plot->setContextMenuPolicy(Qt::CustomContextMenu);
326 impl->m_plot->setParent(this);
307 327 }
308 328
309 329
@@ -340,7 +360,7 void VisualizationGraphWidget::setFlags(GraphFlags flags)
340 360 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, DateTimeRange range)
341 361 {
342 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 365 // Sets graph properties
346 366 impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables);
@@ -374,7 +394,7 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
374 394
375 395 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
376 396 plottableIt != plottableEnd;) {
377 ui->widget->removePlottable(plottableIt->second);
397 impl->m_plot->removePlottable(plottableIt->second);
378 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 404 // Updates graph
385 ui->widget->replot(QCustomPlot::rpQueuedReplot);
405 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
386 406 }
387 407
388 408 std::vector<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const
@@ -403,12 +423,12 void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable)
403 423 return;
404 424 }
405 425
406 VisualizationGraphHelper::setYAxisRange(variable, *ui->widget);
426 VisualizationGraphHelper::setYAxisRange(variable, *impl->m_plot);
407 427 }
408 428
409 429 DateTimeRange VisualizationGraphWidget::graphRange() const noexcept
410 430 {
411 auto graphRange = ui->widget->xAxis->range();
431 auto graphRange = impl->m_plot->xAxis->range();
412 432 return DateTimeRange{graphRange.lower, graphRange.upper};
413 433 }
414 434
@@ -418,8 +438,8 void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool ca
418 438 impl->m_IsCalibration = true;
419 439 }
420 440
421 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
422 ui->widget->replot(QCustomPlot::rpQueuedReplot);
441 impl->m_plot->xAxis->setRange(range.m_TStart, range.m_TEnd);
442 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
423 443
424 444 if (calibration) {
425 445 impl->m_IsCalibration = false;
@@ -496,22 +516,22 void VisualizationGraphWidget::undoZoom()
496 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 520 axis->scaleRange(factor, axis->pixelToCoord(center));
501 521 if (orientation == Qt::Horizontal)
502 522 impl->setRange(axis->range());
503 ui->widget->replot(QCustomPlot::rpQueuedReplot);
523 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
504 524 }
505 525
506 526 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation)
507 527 {
508 auto oldRange = ui->widget->xAxis->range();
509 QCPAxis *axis = ui->widget->axisRect()->rangeDragAxis(orientation);
510 if (ui->widget->xAxis->scaleType() == QCPAxis::stLinear) {
528 auto oldRange = impl->m_plot->xAxis->range();
529 QCPAxis *axis = impl->m_plot->axisRect()->rangeDragAxis(orientation);
530 if (impl->m_plot->xAxis->scaleType() == QCPAxis::stLinear) {
511 531 double rg = (axis->range().upper - axis->range().lower) * (factor / 10);
512 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 535 int start = 0, stop = 0;
516 536 double diff = 0.;
517 537 if (factor > 0.0) {
@@ -524,12 +544,12 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation)
524 544 stop = 2 * this->width() * factor / 10;
525 545 }
526 546 diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop);
527 axis->setRange(ui->widget->axisRect()->rangeDragAxis(orientation)->range().lower * diff,
528 ui->widget->axisRect()->rangeDragAxis(orientation)->range().upper * diff);
547 axis->setRange(impl->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower * diff,
548 impl->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper * diff);
529 549 }
530 550 if (orientation == Qt::Horizontal)
531 551 impl->setRange(axis->range());
532 ui->widget->replot(QCustomPlot::rpQueuedReplot);
552 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
533 553 }
534 554
535 555 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
@@ -579,7 +599,7 QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const
579 599 {
580 600 auto mimeData = new QMimeData;
581 601
582 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot());
602 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position);
583 603 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
584 604 && selectionZoneItemUnderCursor) {
585 605 mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange(
@@ -599,7 +619,7 QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const
599 619
600 620 QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition)
601 621 {
602 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot());
622 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition);
603 623 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
604 624 && selectionZoneItemUnderCursor) {
605 625
@@ -731,7 +751,7 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
731 751 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
732 752 {
733 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 755 zoom(factor, event->pos().y(), Qt::Vertical);
736 756 }
737 757 }
@@ -739,7 +759,7 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
739 759 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
740 760 {
741 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 763 zoom(factor, event->pos().x(), Qt::Horizontal);
744 764 }
745 765 }
@@ -753,19 +773,17 void VisualizationGraphWidget::wheelEvent(QWheelEvent *event)
753 773
754 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);
759 _dragLastPos = event->pos();
778 impl->updateZoomRect(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())};
764 impl->m_DrawingZoomRect->bottomRight->setCoords(pos);
782 impl->updateZoneRect(event->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 788 else
771 789 {
@@ -777,7 +795,18 void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent *event)
777 795
778 796 void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event)
779 797 {
780 setCursor(Qt::ArrowCursor);
798 if(impl->isDrawingZoomRect())
799 {
800 impl->applyZoomRect();
801 }
802 else if(impl->isDrawingZoneRect())
803 {
804 impl->endDrawingZone(this);
805 }
806 else
807 {
808 setCursor(Qt::ArrowCursor);
809 }
781 810 QWidget::mouseReleaseEvent(event);
782 811 }
783 812
@@ -786,9 +815,27 void VisualizationGraphWidget::mousePressEvent(QMouseEvent *event)
786 815 if (event->button() == Qt::LeftButton) {
787 816 if (event->modifiers() == Qt::ControlModifier) {
788 817 }
789 else {
790 setCursor(Qt::ClosedHandCursor);
791 this->_dragLastPos = event->pos();
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:
836 setCursor(Qt::ClosedHandCursor);
837 impl->updateMousePosition(event->pos());
838 }
792 839 }
793 840 }
794 841 else if (event->button()==Qt::RightButton)
@@ -828,8 +875,8 void VisualizationGraphWidget::keyPressEvent(QKeyEvent *event)
828 875 case Qt::Key_Shift:
829 876 break;
830 877 case Qt::Key_M:
831 ui->widget->rescaleAxes();
832 ui->widget->replot(QCustomPlot::rpQueuedReplot);
878 impl->m_plot->rescaleAxes();
879 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
833 880 break;
834 881 case Qt::Key_Left:
835 882 if (event->modifiers() != Qt::ControlModifier) {
@@ -871,7 +918,7 void VisualizationGraphWidget::keyPressEvent(QKeyEvent *event)
871 918
872 919 QCustomPlot &VisualizationGraphWidget::plot() const noexcept
873 920 {
874 return *ui->widget;
921 return *impl->m_plot;
875 922 }
876 923
877 924 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
@@ -896,7 +943,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
896 943 }
897 944
898 945 // Selection Zone Actions
899 auto selectionZoneItem = impl->selectionZoneAt(pos, plot());
946 auto selectionZoneItem = impl->selectionZoneAt(pos);
900 947 if (selectionZoneItem) {
901 948 auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems();
902 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 1016 void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept
1003 1017 {
1004 1018 impl->m_RenderingDelegate->onMouseDoubleClick(event);
@@ -1009,7 +1023,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1009 1023 // Handles plot rendering when mouse is moving
1010 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 1028 // Zoom box and zone drawing
1015 1029 if (impl->m_DrawingZoomRect) {
@@ -1030,7 +1044,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1030 1044 }
1031 1045
1032 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 1048 if (selectionZoneItemUnderCursor && !impl->m_DrawingZone
1035 1049 && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) {
1036 1050
@@ -1065,7 +1079,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
1065 1079 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
1066 1080 {
1067 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 1083 return;
1070 1084 }
1071 1085
@@ -1081,7 +1095,7 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
1081 1095 zoomOrientations.setFlag(Qt::Horizontal, isZoomX);
1082 1096 zoomOrientations.setFlag(Qt::Vertical, isZoomY);
1083 1097
1084 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
1098 impl->m_plot->axisRect()->setRangeZoom(zoomOrientations);
1085 1099
1086 1100 if (!isZoomX && !isZoomY) {
1087 1101 auto axis = plot().axisRect()->axis(QCPAxis::atBottom);
@@ -1108,11 +1122,11 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
1108 1122 if (!isDragDropClick && isLeftClick) {
1109 1123 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) {
1110 1124 // Starts a zoom box
1111 impl->startDrawingRect(event->pos(), plot());
1125 impl->startDrawingRect(event->pos());
1112 1126 }
1113 1127 else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) {
1114 1128 // Starts a new selection zone
1115 auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot());
1129 auto zoneAtPos = impl->selectionZoneAt(event->pos());
1116 1130 if (!zoneAtPos) {
1117 1131 impl->startDrawingZone(event->pos(), this);
1118 1132 }
@@ -1126,7 +1140,7 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
1126 1140 // Selection / Deselection
1127 1141 if (isSelectionZoneMode) {
1128 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 1146 if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected()
@@ -1165,7 +1179,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1165 1179 auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(),
1166 1180 impl->m_DrawingZoomRect->bottomRight->coords().y()};
1167 1181
1168 impl->removeDrawingRect(plot());
1182 impl->removeDrawingRect();
1169 1183
1170 1184 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
1171 1185 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) {
@@ -1184,7 +1198,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1184 1198 = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones;
1185 1199 if (isSelectionZoneMode) {
1186 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 1202 if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton
1189 1203 && !impl->m_HasMovedMouse) {
1190 1204
@@ -1238,7 +1252,7 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
1238 1252
1239 1253 void VisualizationGraphWidget::onDataCacheVariableUpdated()
1240 1254 {
1241 auto graphRange = ui->widget->xAxis->range();
1255 auto graphRange = impl->m_plot->xAxis->range();
1242 1256 auto dateTime = DateTimeRange{graphRange.lower, graphRange.upper};
1243 1257
1244 1258 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
@@ -26,26 +26,8
26 26 <property name="bottomMargin">
27 27 <number>0</number>
28 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 29 </layout>
40 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 31 <resources/>
50 32 <connections/>
51 33 </ui>
General Comments 0
You need to be logged in to leave comments. Login now